Quickly unnest vectors nested in list columns. Still experimental (has some potentially unexpected behavior in some situations)!

dt_hoist(dt_, ...)

Arguments

dt_

the data table to unnest

...

the columns to unnest (must all be the sample length when unnested); use bare names of the variables

Examples


library(data.table)
dt <- data.table(
  x = rnorm(1e5),
  y = runif(1e5),
  nested1 = lapply(1:10, sample, 10, replace = TRUE),
  nested2 = lapply(c("thing1", "thing2"), sample, 10, replace = TRUE),
  id = 1:1e5
)

dt_hoist(dt, nested1, nested2)
#>                   x         y     id nested1 nested2
#>               <num>     <num>  <int>   <int>  <char>
#>       1: -0.8366140 0.3524109      1       1  thing1
#>       2: -0.8366140 0.3524109      1       1  thing1
#>       3: -0.8366140 0.3524109      1       1  thing1
#>       4: -0.8366140 0.3524109      1       1  thing1
#>       5: -0.8366140 0.3524109      1       1  thing1
#>      ---                                            
#>  999996:  0.3999232 0.4907574 100000       7  thing2
#>  999997:  0.3999232 0.4907574 100000       5  thing2
#>  999998:  0.3999232 0.4907574 100000       4  thing2
#>  999999:  0.3999232 0.4907574 100000       4  thing2
#> 1000000:  0.3999232 0.4907574 100000       1  thing2