【发布时间】:2020-10-07 17:25:28
【问题描述】:
我的列表如下所示:
City | Country | TrainArrivals
A | country_1 | 8.00, 9.30, 10.00, 15.15
B | country_1 | 11.00, 12.30, 18.00, 22.20, 22.50
C | country_2 | 8.10, 11.20, 13.00, 16.40, 19.20, 23.00
所以它全部保存为一个列表(称为data)。这里我必须指出data$TrainArrivals 也是list 类型并且长度不同。
我已尝试寻找一些解决方案like this one. 或致电此行:
capture.output(summary(data), file = paste(path, "values.csv", sep = "/"))
但是.csv 文件没有数据,而是信息的类型,长度是每一列。
我尝试调用此行:do.call("rbind", lapply(data, as.data.frame)),但出现以下错误
错误(函数(...,row.names = NULL,check.rows = FALSE, check.names = TRUE, : 参数暗示不同的行数:
那么,有人知道我该如何解决这个问题吗?
EDIT 所以 dput(data)
的输出 structure(list(scenario = "first", pr = "all", rep = "2",
plot_data = list(c(81677L, 91437L, 233376L, 71580L, 43126L,
28724L, 15453L, 11162L, 8355L, 6786L, 5756L, 5162L, 4473L,
3848L, 3617L, 3331L, 2941L, 2572L, 2289L, 1974L, 1797L, 1575L,
1325L, 1217L, 1012L, 886L, 787L, 709L, 548L, 409L, 399L,
339L, 292L, 215L, 128L, 113L, 83L, 61L, 42L, 30L, 18L, 15L,
6L, 12L, 4L, 1L, 0L, 1L, 1L, 0L, 1L))), .Names = c("first",
"pr", "rep", "plot_data"), row.names = c(NA, -1L), groups = structure(list(
scenario = "first", pr = "all", .rows = structure(list(
1L), ptype = integer(0), class = c("vctrs_list_of", "vctrs_vctr",
"list"))), .Names = c("scenario", "pr", ".rows"), row.names = 1L, class = c("tbl_df",
"tbl", "data.frame"), .drop = TRUE), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"))
期望的输出
City; Country; trainArrivals;
A;country_1;8.00, 9.30, 10.00, 15.15;
B;country_1;11.00, 12.30, 18.00, 22.20, 22.50;
C;country_2;8.10, 11.20, 13.00, 16.40, 19.20, 23.00;
【问题讨论】:
-
是
list,还是带有列表列的data.frame?如果您在此处提供dput(data)的输出,可能会有很大帮助。 -
@r2evans 我有一个问题,我为我的实际问题做了一个简单的例子。当我尝试发布原始问题的 dput 时,我得到“正文限制为 30000 个字符;您输入了 36646。”
-
dput(head(data,3))或dput(data[1:3,1:4])?我们不需要所有的数据,我们真的需要足够来表达重点。 :-) -
好吧,我做了 dput(data[3,]),我认为应该可以解决问题
标签: r