[R] Using multiple objects in a for loop

Ales Ziberna aleszib at gmail.com
Sat Nov 25 11:21:08 CET 2006


You should use
assign("temp",get(on[j]))

or just
temp<-get(on[j])

as the on[j] IS just a character string. If you want to get the object 
with that name, use get.


Ales Ziberna

Daniel Yanosky pravi:
> I have a situation where I want to perform the same manipulations to multiple R objects in series. I have constructed a vector () to serve as a list of the objects. However, my assign() assigns the object name (on[j]) as a character string to "temp" and not the object itself.
> 
> =======================================
> 
> fn<-c("FT1.1.01.RData","FT1.1.02.RData")
> 
> on<-c("FT1101","FT1102")
> 
> b<-1
> e<-2
> 
> for (i in 1:2){
> 
> 	for (j in b:e){
> 
> load(fn[j])
> assign("temp",on[j])
> 
> .
> .
> .
> rm(paste(stderr[i],".t",sep=""))
> rm(temp)
> rm(fn[i])
> }
> 
> }
> 
> ===================================
> 
> Daniel
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list