tidyr (version 0.2.0)

unnest: Unnest a list column.

Description

If you have a list-column, this makes each element of the list it's own row.

Usage

unnest(data, col = NULL)

Arguments

data
A data frame.
col
Name of column that needs to be unnested.

Examples

Run this code
library(dplyr)
df <- data.frame(
  x = 1:3,
  y = c("a", "d,e,f", "g,h"),
  stringsAsFactors = FALSE
)
df %>%
  transform(y = strsplit(y, ",")) %>%
  unnest(y)

# You can also unnest lists
my_list <- lapply(split(subset(iris, select = -Species), iris$Species), "[", 1:2, )
unnest(my_list)
unnest(my_list, Species)

Run the code above in your browser using DataLab