[英]R: Make character string refer to an object
I have a large list of files ( file1
, file2
, file3
, etc.) and, for each analysis, I want to refer to two files from this list (eg function(file1,file2)
).我有一个很大的文件列表(
file1
、 file2
、 file3
等),对于每个分析,我想引用这个列表中的两个文件(例如function(file1,file2)
)。 When I try to do this using paste0("file", pairs[1,x]
I get back the character string "file1"
rather than the object file1
.当我尝试使用
paste0("file", pairs[1,x]
执行此操作时,我得到字符串"file1"
而不是对象file1
。
How can I refer to the objects rather than create a character string?如何引用对象而不是创建字符串?
Thank you very much!非常感谢!
Additional comment:附加评论:
How to get the variable from a string containing the variable name: 如何从包含变量名称的字符串中获取变量:
> a = 10
> string = "a"
> string
[1] "a"
> eval(parse(text = string))
[1] 10
> eval(parse(text = "a"))
[1] 10
Hope this helps. 希望这可以帮助。
Are you looking for get()
??? 您是否在寻找
get()
?
a <- 1:5
> get("a")
[1] 1 2 3 4 5
另一种选择:eval(as.name("file"))。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.