[英]how to select a dataframe in R by using a string
If I have a lots of dataframes which are called Df001
, Df002
, Df003
,..., Df100
. 如果我有很多称为
Df001
, Df002
, Df003
,..., Df100
的数据帧。
How could I access a specific location in every dataframe. 如何访问每个数据框中的特定位置。
For example, I want to assign: 例如,我要分配:
Df001[1, 3] = a
Df002[2, 4] = b
...
(a,b are some values read from a file) (a,b是从文件中读取的一些值)
But I don't want to type this codes in details because there are many dataframes needed to be assigned. 但是我不想详细输入此代码,因为需要分配许多数据框。
Are there some methods that use string to select a dataframe and assign value? 是否有一些使用字符串选择数据框和分配值的方法?
The comment by @MrFlick is appropriate - you should turn all of these into a list or something. @MrFlick的注释是适当的-您应该将所有这些都转换为列表或其他内容。
But if you really want to do what you asked, then looping through assign()
commands would work. 但是,如果您真的想做您想做的事,那么遍历
assign()
命令就可以了。 Something like this (it can probably be made prettier): 像这样(可能更漂亮):
for (i in 1:100) {
tmp.name <- paste0("Df", paste0(paste0(rep("0", 3 - nchar(i)), collapse=""), i))
tmp.df <- get(tmp.name)
tmp.df[1, 3] = a
assign(tmp.name, tmp.df)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.