将列表添加为一列列表到数据范围列表
我有一个dataframes t_b_name
的列表和列表t
的列表。现在,我想在保存列表格式时将t
的每个列表添加到t_b_name
的列中。因此,t_b_name
将在每个列表中有一个附加的列,例如value
。我该怎么做?这是输入。
t_b_name <-
list(structure(list(ticker = c("PGN", "NRUC", "FON-CapCorp",
"CUM", "WY"), shortname = c("Progress Engy Inc", "Natl Rural Utils Coop Fin Corp",
"Sprint Cap Corp", "Cummins Inc", "Weyerhaeuser Co"), redcode = c("7B7589",
"69AB75", "8D7266", "2F4123", "9F837C"), sector = c("Utilities",
"Financials", "Telecommunications Services", "Industrials", "Basic Materials"
), region = c("N.Amer", "N.Amer", "N.Amer", "N.Amer", "N.Amer"
)), row.names = c(55529L, 54997L, 44861L, 40620L, 63060L), class = "data.frame"),
structure(list(ticker = c("GLW", "DPL", "ETN", "CBE", "R"
), shortname = c("Corning Inc", "DPL Inc", "Eaton Corp",
"Cooper Inds Ltd", "Ryder Sys Inc"), redcode = c("23AC85",
"2F65BC", "29F85D", "GI659A", "7FB89D"), sector = c("Technology",
"Utilities", "Industrials", "Industrials", "Industrials"),
region = c("N.Amer", "N.Amer", "N.Amer", "N.Amer", "N.Amer"
)), row.names = c(20935L, 41188L, 44529L, 39663L, 55918L
), class = "data.frame"), structure(list(ticker = c("PHHCO",
"CIN", "MCCC-MedcomLLC", "FON-CapCorp", "AXL-Inc"), shortname = c("PHH Corp",
"CINergy Corp", "Mediacom LLC", "Sprint Cap Corp", "Amern Axle & Mfg Inc"
), redcode = c("6FC652", "1I96BB", "UZDA8D", "8D7266", "UU2679"
), sector = c("Financials", "Utilities", "Consumer Services",
"Telecommunications Services", "Consumer Goods"), region = c("N.Amer",
"N.Amer", "N.Amer", "N.Amer", "N.Amer")), row.names = c(55564L,
22422L, 51792L, 44861L, 38727L), class = "data.frame"))
t <- list(c(X171 = -4.84310809694633, X161 = -3.36603783246705, X112 = -2.72493266607287,
X87 = -2.58575358943995, X210 = -2.01054909486918), c(X20 = -2.30989551860346,
X98 = -2.19943312429299, X104 = -1.61663388964235, X72 = -1.31631234805403,
X176 = -1.24859298915501), c(X172 = -2.67718752034399, X28 = -2.27605041741808,
X151 = -2.25609160045945, X112 = -2.04810033395225, X57 = -1.61378307188531
))
I have a list of dataframes t_b_name
and a list of list t
. Now I want to add each list of t
as a column to t_b_name
while conserving the list format. So the t_b_name
would have an additional column in each list, named, let's say, value
. How can I do this? Here's the input.
t_b_name <-
list(structure(list(ticker = c("PGN", "NRUC", "FON-CapCorp",
"CUM", "WY"), shortname = c("Progress Engy Inc", "Natl Rural Utils Coop Fin Corp",
"Sprint Cap Corp", "Cummins Inc", "Weyerhaeuser Co"), redcode = c("7B7589",
"69AB75", "8D7266", "2F4123", "9F837C"), sector = c("Utilities",
"Financials", "Telecommunications Services", "Industrials", "Basic Materials"
), region = c("N.Amer", "N.Amer", "N.Amer", "N.Amer", "N.Amer"
)), row.names = c(55529L, 54997L, 44861L, 40620L, 63060L), class = "data.frame"),
structure(list(ticker = c("GLW", "DPL", "ETN", "CBE", "R"
), shortname = c("Corning Inc", "DPL Inc", "Eaton Corp",
"Cooper Inds Ltd", "Ryder Sys Inc"), redcode = c("23AC85",
"2F65BC", "29F85D", "GI659A", "7FB89D"), sector = c("Technology",
"Utilities", "Industrials", "Industrials", "Industrials"),
region = c("N.Amer", "N.Amer", "N.Amer", "N.Amer", "N.Amer"
)), row.names = c(20935L, 41188L, 44529L, 39663L, 55918L
), class = "data.frame"), structure(list(ticker = c("PHHCO",
"CIN", "MCCC-MedcomLLC", "FON-CapCorp", "AXL-Inc"), shortname = c("PHH Corp",
"CINergy Corp", "Mediacom LLC", "Sprint Cap Corp", "Amern Axle & Mfg Inc"
), redcode = c("6FC652", "1I96BB", "UZDA8D", "8D7266", "UU2679"
), sector = c("Financials", "Utilities", "Consumer Services",
"Telecommunications Services", "Consumer Goods"), region = c("N.Amer",
"N.Amer", "N.Amer", "N.Amer", "N.Amer")), row.names = c(55564L,
22422L, 51792L, 44861L, 38727L), class = "data.frame"))
t <- list(c(X171 = -4.84310809694633, X161 = -3.36603783246705, X112 = -2.72493266607287,
X87 = -2.58575358943995, X210 = -2.01054909486918), c(X20 = -2.30989551860346,
X98 = -2.19943312429299, X104 = -1.61663388964235, X72 = -1.31631234805403,
X176 = -1.24859298915501), c(X172 = -2.67718752034399, X28 = -2.27605041741808,
X151 = -2.25609160045945, X112 = -2.04810033395225, X57 = -1.61378307188531
))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
map()
+cbind
(或map()
+data.frame.frame
):输出
You could use
Map()
+cbind
(orMap()
+data.frame
):which is equivalent to
Output
您可以尝试
You may try