Analogous function for nest
and unnest
in tidyr
nest_dt(data, ...) unnest_dt(data, col)
data | data.table, nested or unnested |
---|---|
... | The variable for nest group |
col | The variable of nested data to be unnest |
data.table, nested or unnested
In the nest_dt
, the data would be nested to a column named `ndt`,
which is short for nested data.table.
https://www.r-bloggers.com/much-faster-unnesting-with-data-table/
https://stackoverflow.com/questions/25430986/create-nested-data-tables-by-collapsing-rows-into-new-data-tables
iris %>% nest_dt(Species) -> nested_iris nested_iris#> Species ndt #> 1: setosa <data.table> #> 2: versicolor <data.table> #> 3: virginica <data.table>nested_iris %>% unnest_dt(ndt) -> unnested_iris unnested_iris#> Species Sepal.Length Sepal.Width Petal.Length Petal.Width #> 1: setosa 5.1 3.5 1.4 0.2 #> 2: setosa 4.9 3.0 1.4 0.2 #> 3: setosa 4.7 3.2 1.3 0.2 #> 4: setosa 4.6 3.1 1.5 0.2 #> 5: setosa 5.0 3.6 1.4 0.2 #> --- #> 146: virginica 6.7 3.0 5.2 2.3 #> 147: virginica 6.3 2.5 5.0 1.9 #> 148: virginica 6.5 3.0 5.2 2.0 #> 149: virginica 6.2 3.4 5.4 2.3 #> 150: virginica 5.9 3.0 5.1 1.8