r - Flatten list column in data frame with ID column -


my data frame contains output of survey select multiple question type. cells have multiple values.

df <- data.frame(a=1:3,b=i(list(1,1:2,1:3))) df         b 1 1       1 2 2    1, 2 3 3 1, 2, 3 

i flatten out list obtain following output:

df         b 1 1       1 2 2       1 3 2       2 4 3       1 5 3       2 6 3       3 

should easy somehow can't find search terms. thanks.

you can use unnest "tidyr":

library(tidyr) unnest(df, b) #   b # 1 1 1 # 2 2 1 # 3 2 2 # 4 3 1 # 5 3 2 # 6 3 3 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -