简体   繁体   English

在循环inR中更改对象名称

[英]change object name in loop inR

I have a for loop which reads in a different RData file in each iteration and that works well with just paste. 我有一个for循环,该循环在每次迭代中读取不同的RData文件,并且只需粘贴即可很好地工作。 However, once the RData file is loaded there is an object loaded called topy in the first instance of the loop, in the second it is ropy, then eopy and so on. 但是,一旦加载RData文件,则在循环的第一个实例中加载了一个名为topy的对象,在第二个实例中,该对象是ropy,然后是eopy,依此类推。 What I now tried is 我现在尝试的是

vals<-c("topy","ropy","eopy")


paste("vals[i]")->r

to assign these different objects to r which is used further in the script and is overwirtten in every step of the loop. 将这些不同的对象分配给r,该r在脚本中会进一步使用,并且在循环的每个步骤中都被覆盖。 But that does not work. 但这不起作用。 Topy and ropy and the rest ar matrixes. Topy和ropy,其余为ar矩阵。 When I load the RData file and then just type manually topy the matrix will be shown but if I do paste and then type r it will only show "topy". 当我加载RData文件,然后手动键入topy时,将显示矩阵,但是如果我粘贴然后键入r,它将仅显示“ topy”。 I also tried assign - did not work..any idea? 我也尝试分配-没有用..任何想法?

I'm not sure whether I got your point, is the following what you need? 我不确定我是否明白你的意思,下面是你所需要的吗?

p <-parse(text=vals[i])
r <- eval(p)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM