The simplest way to convert a list with various length vectors to a data.frame in R

前端 未结 3 1048
眼角桃花
眼角桃花 2020-12-01 20:33

Here I have a list with different length vectors. And I\'d want to get a data.frame. I\'ve seen lots of posts about it in SO (see ref), but none of them are as simple as I e

3条回答
  •  感情败类
    2020-12-01 21:00

    Make this function:

    listToDF <- function(aa){
      sapply(aa, "length<-", max(lengths(aa)))
     }
    

    Then use it, simply:

    listToDF(aa)
    

提交回复
热议问题