Learn R Programming

tidyfst (version 0.7.7)

nest_by: Nest and unnest

Description

Analogous function for nest and unnest in tidyr. unnest_col will automatically remove other list-columns except for the target list-column (which would be unnested later).

Usage

nest_by(data, group = NULL, negate = FALSE)

unnest_col(data, col)

Arguments

data

data.table, nested or unnested

group

The variable for nest group, could recieve character vector or regular expression.

negate

Applicable when the "group" parameter uses regular expression, if TRUE, return non-matching elements.

col

The single variable of nested data to be unnested

Value

data.table, nested or unnested

Details

In the nest_dt, the data would be nested to a column named `ndt`, which is short for nested data.table.

References

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

See Also

nest

Examples

Run this code
# NOT RUN {
mtcars %>% nest_by("cyl")
mtcars %>% nest_by("cyl|vs")
mtcars %>% nest_by(c("cyl","vs"))

mtcars %>% nest_by("cyl|vs") %>%
  unnest_col(ndt)
# }

Run the code above in your browser using DataLab