У меня есть список списков списков списков (я знаю, много списков, всего около 6000 DataFrames).Первый список определяет начальный месяц (с января по декабрь), второй - год (2002 - 2018), третий - различные сектора (например, основные товары для потребителя, всего 10), а последний - квантиль (С 1 по 5).
Для большей ясности: sector_prtf[["StartMonth"]][["Year"]][["Sector"]][["Quantile"]]
Вот пример того, как выглядят фреймы данных:
sector_prtf[[1]][[1]][[1]][[1]]
Growth quantile Sector
2002-01-31 0.2278331 1 Consumer Discretionary
sector_prtf[[1]][[1]][[2]][[1]]
Growth quantile Sector
2002-01-31 0.09700046 1 Consumer Staples
sector_prtf[[1]][[2]][[1]][[1]]
Growth quantile Sector
2003-01-31 -0.1081433 1 Consumer Discretionary
sector_prtf[[2]][[1]][[1]][[1]]
Growth quantile Sector
2002-02-28 0.3596547 1 Consumer Discretionary
Цель состоит в том, чтобы объединить списки таким образом, чтобысектора вместе с квантилем и соответствующей начальной датой.
Growth quantile Sector
2002-01-31 0.2278331 1 Consumer Discretionary
Growth quantile Sector
2003-01-31 -0.1081433 1 Consumer Discretionary
Growth quantile Sector
2004-01-30 0.6446954 1 Consumer Discretionary
.
.
.
Growth quantile Sector
2017-01-31 0.1824898 1 Consumer Discretionary
Как я уже говорил, это должно быть сделано для каждого сектора и каждой начальной даты.
Я попытался объединить списки, выполнив простые rbinds:
merged_sector <- lapply(sector_prtf, function(a) lapply(a, function(b) lapply(b, function(c) do.call("rbind", c))))
merged_sector <- lapply(merged_sector, function(a) lapply(a, function(b) do.call("rbind", b)))
merged_sector <- lapply(merged_sector, function(a) do.call("rbind", a))
merged_sector <- do.call("rbind", merged_sector)
После этого объединенные списки выглядят следующим образом:
.
.
.
2012-01-319 -1.030502e-02 1 Materials
2012-01-3117 3.039239e-02 2 Materials
2012-01-3127 6.278972e-02 3 Materials
2012-01-3110 1.150880e-01 1 Real Estate
2012-01-3118 9.337119e-02 2 Real Estate
2012-01-3128 3.242025e-02 3 Real Estate
2012-01-3119 6.044756e-02 1 Utilities
2012-01-31110 1.154916e-01 2 Utilities
2012-01-3129 1.156366e-01 3 Utilities
2013-01-31 2.797345e-01 1 Consumer Discretionary
2013-01-311 1.875079e-01 2 Consumer Discretionary
2013-01-312 3.652037e-01 3 Consumer Discretionary
.
.
.
Моя идея заключалась в том, чтобы отфильтровать объединенный DF по секторам и квантилям, но даты представляют огромную проблему (уникальные имена строк).
Возможно, естьболее простой способ решить эту проблему?Заранее спасибо
* Обновление: вот ссылка на запрошенный файл dput
.Он включает в себя только первый начальный месяц (январь): https://ufile.io/y80fb
** Правка 2: Приносим извинения за неудобства, вызванные не предоставлением воспроизводимого примера.
list(list(list(structure(list(Growth = 0.227833070205427, quantile = structure(1L, .Label = "1", class = "factor"),
Sector = structure(1L, .Label = "Consumer Discretionary", class = "factor")), class = "data.frame", row.names = "2002-01-31"),
structure(list(Growth = 0.00580189434527657, quantile = structure(1L, .Label = "2", class = "factor"),
Sector = structure(1L, .Label = "Consumer Discretionary", class = "factor")), class = "data.frame", row.names = "2002-01-31"),
structure(list(Growth = 0.280654630370414, quantile = structure(1L, .Label = "3", class = "factor"),
Sector = structure(1L, .Label = "Consumer Discretionary", class = "factor")), class = "data.frame", row.names = "2002-01-31")),
list(structure(list(Growth = 0.0970004606893047, quantile = structure(1L, .Label = "1", class = "factor"),
Sector = structure(1L, .Label = "Consumer Staples", class = "factor")), class = "data.frame", row.names = "2002-01-31"),
structure(list(Growth = 0.054821203483339, quantile = structure(1L, .Label = "2", class = "factor"),
Sector = structure(1L, .Label = "Consumer Staples", class = "factor")), class = "data.frame", row.names = "2002-01-31"),
structure(list(Growth = 0.00837169953085215, quantile = structure(1L, .Label = "3", class = "factor"),
Sector = structure(1L, .Label = "Consumer Staples", class = "factor")), class = "data.frame", row.names = "2002-01-31")),
list(structure(list(Growth = -0.078767963284149, quantile = structure(1L, .Label = "1", class = "factor"),
Sector = structure(1L, .Label = "Energy", class = "factor")), class = "data.frame", row.names = "2002-01-31"),
structure(list(Growth = -0.069104950106169, quantile = structure(1L, .Label = "2", class = "factor"),
Sector = structure(1L, .Label = "Energy", class = "factor")), class = "data.frame", row.names = "2002-01-31"),
structure(list(Growth = -0.27207135756175, quantile = structure(1L, .Label = "3", class = "factor"),
Sector = structure(1L, .Label = "Energy", class = "factor")), class = "data.frame", row.names = "2002-01-31")),
list(structure(list(Growth = 0.009642535558954, quantile = structure(1L, .Label = "1", class = "factor"),
Sector = structure(1L, .Label = "Financials", class = "factor")), class = "data.frame", row.names = "2002-01-31"),
structure(list(Growth = 0.0117244867054771, quantile = structure(1L, .Label = "2", class = "factor"),
Sector = structure(1L, .Label = "Financials", class = "factor")), class = "data.frame", row.names = "2002-01-31"),
structure(list(Growth = -0.185284889832411, quantile = structure(1L, .Label = "3", class = "factor"),
Sector = structure(1L, .Label = "Financials", class = "factor")), class = "data.frame", row.names = "2002-01-31")),
list(structure(list(Growth = 0.239390715659085, quantile = structure(1L, .Label = "1", class = "factor"),
Sector = structure(1L, .Label = "Health Care", class = "factor")), class = "data.frame", row.names = "2002-01-31"),
structure(list(Growth = -0.0162271493055311, quantile = structure(1L, .Label = "2", class = "factor"),
Sector = structure(1L, .Label = "Health Care", class = "factor")), class = "data.frame", row.names = "2002-01-31"),
structure(list(Growth = -0.067303679327545, quantile = structure(1L, .Label = "3", class = "factor"),
Sector = structure(1L, .Label = "Health Care", class = "factor")), class = "data.frame", row.names = "2002-01-31")),
list(structure(list(Growth = 0.0620349870410483, quantile = structure(1L, .Label = "1", class = "factor"),
Sector = structure(1L, .Label = "Industrials", class = "factor")), class = "data.frame", row.names = "2002-01-31"),
structure(list(Growth = 0.0821803720980501, quantile = structure(1L, .Label = "2", class = "factor"),
Sector = structure(1L, .Label = "Industrials", class = "factor")), class = "data.frame", row.names = "2002-01-31"),
structure(list(Growth = 0.137729664907273, quantile = structure(1L, .Label = "3", class = "factor"),
Sector = structure(1L, .Label = "Industrials", class = "factor")), class = "data.frame", row.names = "2002-01-31")),
list(structure(list(Growth = -0.0843930112785794, quantile = structure(1L, .Label = "1", class = "factor"),
Sector = structure(1L, .Label = "Information Technology", class = "factor")), class = "data.frame", row.names = "2002-01-31"),
structure(list(Growth = -0.172018997118367, quantile = structure(1L, .Label = "2", class = "factor"),
Sector = structure(1L, .Label = "Information Technology", class = "factor")), class = "data.frame", row.names = "2002-01-31"),
structure(list(Growth = -0.298718947065689, quantile = structure(1L, .Label = "3", class = "factor"),
Sector = structure(1L, .Label = "Information Technology", class = "factor")), class = "data.frame", row.names = "2002-01-31")),
list(structure(list(Growth = 0.0170747596874905, quantile = structure(1L, .Label = "1", class = "factor"),
Sector = structure(1L, .Label = "Materials", class = "factor")), class = "data.frame", row.names = "2002-01-31"),
structure(list(Growth = 0.190415482682349, quantile = structure(1L, .Label = "2", class = "factor"),
Sector = structure(1L, .Label = "Materials", class = "factor")), class = "data.frame", row.names = "2002-01-31"),
structure(list(Growth = 0.221341415148432, quantile = structure(1L, .Label = "3", class = "factor"),
Sector = structure(1L, .Label = "Materials", class = "factor")), class = "data.frame", row.names = "2002-01-31")),
list(structure(list(Growth = 0.168638361539387, quantile = structure(1L, .Label = "1", class = "factor"),
Sector = structure(1L, .Label = "Real Estate", class = "factor")), class = "data.frame", row.names = "2002-01-31"),
structure(list(Growth = 0.0810611988754563, quantile = structure(1L, .Label = "2", class = "factor"),
Sector = structure(1L, .Label = "Real Estate", class = "factor")), class = "data.frame", row.names = "2002-01-31"),
structure(list(Growth = 0.0365040437639329, quantile = structure(1L, .Label = "3", class = "factor"),
Sector = structure(1L, .Label = "Real Estate", class = "factor")), class = "data.frame", row.names = "2002-01-31")),
list(structure(list(Growth = 0.111350872628164, quantile = structure(1L, .Label = "1", class = "factor"),
Sector = structure(1L, .Label = "Utilities", class = "factor")), class = "data.frame", row.names = "2002-01-31"),
structure(list(Growth = -0.0978660942657028, quantile = structure(1L, .Label = "2", class = "factor"),
Sector = structure(1L, .Label = "Utilities", class = "factor")), class = "data.frame", row.names = "2002-01-31"),
structure(list(Growth = 0.112770511307641, quantile = structure(1L, .Label = "3", class = "factor"),
Sector = structure(1L, .Label = "Utilities", class = "factor")), class = "data.frame", row.names = "2002-01-31"))))