如何将 lapply 生成的 tibbles 作为 R 中的单独数据帧
How I can get the tibbles generated by lapply as a seperate dataframe in R
我使用 lapply 生成了一个循环。当我 运行 循环时,我得到了像这样的小标题这两个例子,但是为了保存 space,我没有在这里解决 10 个小标题
Color Variables value
Yellow A 12
Red B 11
Blue B 4
… … …
Color Variables value
Red R 6
Black N 8
Green 10
所以我有 10 个由 lapply 连续生成的小标题。
现在,我想为每个人获取一个数据框。所以我将有 10 个数据帧,例如 df1、df2、df3、...
第一个小标题的结果是:
df1
Color Variables value
Yellow A 12
Red B 11
Blue B 4
或者第二个 table 是:
df2
Color Variables value
Red R 6
Black N 8
Green 10
所以我得到 dfs、df1...df10
# create a list of tibbles and store them in a list
dfs <- lapply(1:3, function(i) {
tibble(x = LETTERS[i], y = i)
})
# you can simply access them by index
df1 <- dfs[[1]]
# if you truly want to create all df objects
for (i in seq(dfs))
assign(paste0("df", i), dfs[[i]])
我使用 lapply 生成了一个循环。当我 运行 循环时,我得到了像这样的小标题这两个例子,但是为了保存 space,我没有在这里解决 10 个小标题
Color Variables value
Yellow A 12
Red B 11
Blue B 4
… … …
Color Variables value
Red R 6
Black N 8
Green 10
所以我有 10 个由 lapply 连续生成的小标题。
现在,我想为每个人获取一个数据框。所以我将有 10 个数据帧,例如 df1、df2、df3、...
第一个小标题的结果是: df1
Color Variables value
Yellow A 12
Red B 11
Blue B 4
或者第二个 table 是:
df2
Color Variables value
Red R 6
Black N 8
Green 10
所以我得到 dfs、df1...df10
# create a list of tibbles and store them in a list
dfs <- lapply(1:3, function(i) {
tibble(x = LETTERS[i], y = i)
})
# you can simply access them by index
df1 <- dfs[[1]]
# if you truly want to create all df objects
for (i in seq(dfs))
assign(paste0("df", i), dfs[[i]])