首页 > 解决方案 > 如何在r中导出具有不同大小的列表列表

问题描述

我研究了编写此类列表的方法,但无法实现。

这是我的数据:

a<-structure(list(X2005 = structure(list(hours = list(c(0.2, 0, 
4), c(0.2, 4)), maxx = structure(list(maxh2 = 4, maxh3 = 4), .Names = c("maxh2", 
"maxh3"))), .Names = c("hours", "maxx")), X2006 = structure(list(
    hours = list(c(1.8, 0, 1), c(1.8, 1)), maxx = structure(list(
        maxh2 = 1.8, maxh3 = 1.8), .Names = c("maxh2", "maxh3"
    ))), .Names = c("hours", "maxx")), X2007 = structure(list(
    hours = list(c(4.2, 0, 0), c(4.2, 0)), maxx = structure(list(
        maxh2 = 4.2, maxh3 = 4.2), .Names = c("maxh2", "maxh3"
    ))), .Names = c("hours", "maxx")), X2008 = structure(list(
    hours = list(c(0.1, 6, 0), c(3.1, 3)), maxx = structure(list(
        maxh2 = 6, maxh3 = 3.1), .Names = c("maxh2", "maxh3"))), .Names = c("hours", 
"maxx"))), .Names = c("X2005", "X2006", "X2007", "X2008"))

我需要在 Excel 表中查看此列表列表。

标签: r

解决方案


我们可以试试这个:

write.csv(do.call("rbind",list(unlist(a))),"testme.csv")

你也可以试试这个并reshape2在导出前做一些事情。

write.csv(do.call("cbind",list(unlist(a))),"testme2.csv")

查看这些产生的结构:

View(do.call("cbind",list(unlist(a))))

@jay.sf 建议的另一个选项:

openxlsx::write.xlsx(do.call("rbind",list(unlist(a))),"testme.xlsx")

推荐阅读