I am having a list that looks like this:
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
So it is all saved as a list (called data
). Here I have to point out that data$TrainArrivals
is also of type list
and from different lengths.
I have tried looking for some solutions like this one. Or calling this line:
capture.output(summary(data), file = paste(path, "values.csv", sep = "/"))
but the .csv
file didn't have the data, but instead infromation of which type, length is every column.
I tried calling this line: do.call("rbind", lapply(data, as.data.frame))
and I got the following error
Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, : arguments imply differing number of rows:
So, does anyone have an idea how could I solve the problem?
EDIT So the output from 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"))
Desired output
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;