如何将数据帧索引放入r中的for循环中?

问题描述 投票:0回答:1

我有一个代码,我希望它重复三次,每次我有数据帧的输出为df1,df2,...在这个循环内我有另一个循环,说按行绑定这些数据,我的问题是如何将索引放到“e <-bind_rows(listdf))”(我应该有三个“e”)所以最后我可以绑定三个“e”并有一个数据帧,包括df1,df2,..对于三个重复的指数i。

提前,我非常感谢您的回复。

for (i in 1:3){
(there are some codes in here which uses i as index and gives:)
df1=...
df2=...

listdf<-list()
for (j in 1:20){
z <- j
sdf <- paste("df", z, sep="")
ddf <- get(paste("df", z, sep=""))
listdf[[sdf]] <-ddf
}
e<-bind_rows(listdf)) 

}
r for-loop indexing
1个回答
1
投票

您可以使用assign函数保存每个e,并在旁边添加一个数字。它将是这样的:

assign(paste0("e",i),bind_rows(listdf))

你将最终得到e1e2e3

© www.soinside.com 2019 - 2024. All rights reserved.