Flatten list column in data frame with ID column

前端 未结 4 522
逝去的感伤
逝去的感伤 2021-01-17 11:16

My data frame contains the output of a survey with a select multiple question type. Some cells have multiple values.

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


        
4条回答
  •  无人共我
    2021-01-17 11:43

    You can just use unnest from "tidyr":

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

提交回复
热议问题