0

I have a dataframe with a column where each row is a list. Like this:

> df
 
recipe_id     ingredients      

        1     c("cheese", "milk")
        2     c("egg", "chocolate") 
        3     c("rice", "corn")

And I want to turn it into:

> df
 
recipe_id     ingredients      

        1     cheese
        1     milk
        2     egg
        2     chocolate
        3     rice
        3     corn

Thanks.

1 Answers1

0

We can use unnest in tidyr

library(tidyr)
unnest(df, ingredients)

data

df <- tibble(recipe_id = 1:3, 
   ingredients = list( c("cheese", "milk"), 
        c("egg", "chocolate") ,  c("rice", "corn")))
akrun
  • 874,273
  • 37
  • 540
  • 662