dt_unnest.Rd
Quickly unnest data tables, particularly those nested by dt_nest()
.
dt_unnest(dt_, col, keep = TRUE)
the data table to unnest
the column to unnest
whether to keep the nested column, default is TRUE
library(data.table)
dt <- data.table(
x = rnorm(1e5),
y = runif(1e5),
grp = sample(1L:3L, 1e5, replace = TRUE)
)
nested <- dt_nest(dt, grp)
dt_unnest(nested, col = data)
#> Key: <grp>
#> grp x y data
#> <int> <num> <num> <list>
#> 1: 1 1.0132525 0.02937715 <data.table[33351x2]>
#> 2: 1 1.3222125 0.17566096 <data.table[33351x2]>
#> 3: 1 0.5065119 0.06658542 <data.table[33351x2]>
#> 4: 1 -0.9279822 0.55996602 <data.table[33351x2]>
#> 5: 1 0.7179084 0.85645944 <data.table[33351x2]>
#> ---
#> 99996: 3 0.5534343 0.82439307 <data.table[33394x2]>
#> 99997: 3 -0.5466994 0.59113375 <data.table[33394x2]>
#> 99998: 3 0.0279944 0.50978427 <data.table[33394x2]>
#> 99999: 3 1.9397046 0.40044357 <data.table[33394x2]>
#> 100000: 3 1.4679262 0.38763369 <data.table[33394x2]>