Tidy data.table in Julia

Stable Dev CI Codecov

Dongdong Kong

Installation

using Pkg
Pkg.add(url="https://github.com/jl-spatial/RTableTools.jl")

Functions

RTableTools.freadFunction
fread(file::AbstractString; header=true, kw...)

Arguments

  • file: the csv file to read
  • header: whether the csv file has header?
  • kw: other parameters for CSV.File

Examaple

fread("a.csv")
source
RTableTools.fwriteFunction
fwrite(df, file; kw...)
df = DataFrame(A=1:3, B=4:6, C=7:9)
fwrite(df, "a.csv")
fwrite(df, "a.csv", append=true)
source
Base.mergeFunction
merge(
    x::AbstractDataFrame,
    y::AbstractDataFrame;
    by,
    all,
    all_x,
    all_y,
    makeunique,
    suffixes,
    kw...
) -> Any

Example

d1 = DataFrame(A=1:3, B=4:6, C=7:9)
d2 = DataFrame(A=1:3, B=4:6, D=7:9)
d = merge(d1, d2, by = "A", suffixes=["_tas", ".rh"])
d[:, "B.rh"]

seealso: leftjoin, rightjoin, innerjoin, outerjoin

source
RTableTools.expand_gridFunction
expand_grid(; kw...)

Create a Data Frame from All Combinations of Factor Variables (see R's base::expand.grid)

Return

A DataFrame containing one row for each combination of the supplied argument. The first factors vary fastest.

Examples

julia> dims = (x = 1:2, y = [3, 4], z = ["a", "b", "c"]);

julia> expand_grid(;dims...)
12×3 DataFrame
 Row │ x      y      z      
     │ Int64  Int64  String 
─────┼──────────────────────
   1 │     1      3  a
   2 │     2      3  a
   3 │     1      4  a
   4 │     2      4  a
   5 │     1      3  b
   6 │     2      3  b
   7 │     1      4  b
   8 │     2      4  b
   9 │     1      3  c
  10 │     2      3  c
  11 │     1      4  c
  12 │     2      4  c
source
RTableTools.array2dfFunction
array2df(A, dims)

Examples

julia> dims = (x = 1:2, y = [3, 4], z = ["a", "b", "c"]);
julia> A = rand(2, 2, 3);
julia> array2df(A, dims)
12×4 DataFrame
 Row │ x      y      z       value    
     │ Int64  Int64  String  Float64  
─────┼────────────────────────────────
   1 │     1      3  a       0.62047  
   2 │     2      3  a       0.669467 
   3 │     1      4  a       0.198138 
   4 │     2      4  a       0.522508 
   5 │     1      3  b       0.320988 
   6 │     2      3  b       0.198885 
   7 │     1      4  b       0.780293 
   8 │     2      4  b       0.892373 
   9 │     1      3  c       0.716294 
  10 │     2      3  c       0.562014 
  11 │     1      4  c       0.834089 
  12 │     2      4  c       0.37194  
source