How to convert a list of lists to a dataframe - non-identical lists

前端 未结 3 410
闹比i
闹比i 2020-12-17 05:59

I have a list where each element is a named list, but the elements are not the same everywhere. I have read solutions on how to convert lists of lists to dataframes here and

3条回答
  •  醉酒成梦
    2020-12-17 06:47

    Use lapply to convert your list elements to data.frames and rbind_all that:

    rbind_all(lapply(lisnotOK,data.frame))
       a b     c    d
    1  1 2    hi 
    2 NA 2 hello nope
    Warning message:
    In rbind_all(lapply(lisnotOK, data.frame)) :
      Unequal factor levels: coercing to character
    

    Or from plyr, ldply with data.frame:

    ldply(lisnotOK,data.frame)
       a b     c    d
    1  1 2    hi 
    2 NA 2 hello nope
    

提交回复
热议问题