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
Post a Comment