R list of lists to data.frame

前端 未结 5 1275
夕颜
夕颜 2020-11-27 19:12

I\'ve got a list of lists, call it listHolder, which has length 5.

Every element in listHolder is a list of numeric data, with 160 or so e

5条回答
  •  迷失自我
    2020-11-27 19:43

    This achieves a similar result, but is more intuitive (to me at least)

    #Generate fake data 
    listoflists=list(c(1,'a',3,4),c(5,'b',6,7))
    
    #Convert to a dataframe, transpose, and convert the resulting matrix back to a dataframe
    df= as.data.frame(t(as.data.frame(listoflists)))
    
    #Strip out the rownames if desired
    rownames(df)<-NULL
    
    #Show result
    df
    

提交回复
热议问题