Learn R Programming

tsibble (version 0.4.0)

unnest.lst_ts: Unnest a list column.

Description

Unnest a list column.

Usage

# S3 method for lst_ts
unnest(data, ..., key = id(), .drop = NA, .id = NULL,
  .sep = NULL, .preserve = NULL)

Arguments

data

A lst_ts.

...

Specification of columns to unnest. Use bare variable names or functions of variables. If omitted, defaults to all list-cols.

key

Unquoted variables to create the key (via id) after unnesting.

.drop

Should additional list columns be dropped? By default, unnest will drop them if unnesting the specified columns requires the rows to be duplicated.

.id

Data frame identifier - if supplied, will create a new column with name .id, giving a unique identifier. This is most useful if the list column is named.

.sep

If non-NULL, the names of unnested data frame columns will combine the name of the original list-col with the names from nested data frame, separated by .sep.

.preserve

Optionally, list-columns to preserve in the output. These will be duplicated in the same way as atomic vectors. This has dplyr::select semantics so you can preserve multiple variables with .preserve = c(x, y) or .preserve = starts_with("list").

Value

A tbl_ts.

See Also

tidyr::unnest, nest.tbl_ts for the inverse operation.

Examples

Run this code
# NOT RUN {
nested_ped <- pedestrian %>% 
  nest(-Sensor)
nested_ped %>% 
  unnest(key = id(Sensor))
nested_tourism <- tourism %>% 
  nest(-Region, -State)
nested_tourism %>% 
  unnest(key = id(Region | State))
# }

Run the code above in your browser using DataLab