Combining lists of different lengths into data frame

后端 未结 2 1214
梦如初夏
梦如初夏 2020-12-11 10:38

I have data like the SampleData below, which has lists of different length that I\'d like to combine in to a data frame like the Desired Result below. I\'ve tried using lap

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-11 11:13

    Here is a modified version with length<- assignment

    setNames(do.call(cbind.data.frame, lapply(lapply(SampleData, unlist), 
            `length<-`, max(lengths(SampleData)))), paste0("V", 1:3))
    #  V1 V2 V3
    #1  1  1  3
    #2  2  2  4
    #3  3 NA  6
    #4 NA NA  7
    

提交回复
热议问题