妄徒之命 2010-11-19 16:40 采纳率: 100%
浏览 293
已采纳

R 列表到数据帧

I have a nested list of data. Its length is 132 and each item is a list of length 20. Is there a quick way to convert this structure into a data frame that has 132 rows and 20 columns of data?

Here is some sample data to work with:

l <- replicate(
  132,
  list(sample(letters, 20)),
  simplify = FALSE
)

转载于:https://stackoverflow.com/questions/4227223/r-list-to-data-frame

  • 写回答

17条回答 默认 最新

  • elliott.david 2010-11-19 16:46
    关注

    Assuming your list of lists is called l:

    df <- data.frame(matrix(unlist(l), nrow=132, byrow=T))
    

    The above will convert all character columns to factors, to avoid this you can add a parameter to the data.frame() call:

    df <- data.frame(matrix(unlist(l), nrow=132, byrow=T),stringsAsFactors=FALSE)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(16条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度