[R] Use of variables to reference to objects

Uwe Ligges ligges at statistik.uni-dortmund.de
Fri Nov 22 18:25:21 CET 2002



Kris Nackaerts wrote:
> 
> Hi,
> 
> I'm new to R and looking for a way to use a variable to reference to an
> object.
> 
> I'm plotting several graphs on top of each other and want to do this by
> a for loop. The field I want to graph have names like a1,a2,a3, ...
> I can't figure out how to get this working:
> 
> It should look like this:
> lines(spectral$Wavelength,paste("spectral$a",j,sep=""),col=j)
> 
> but the "paste()" does not seem to work in this context.
> 
> Any help?

1. I suggest to generate a list "a", which can be indexed with a[[j]],
so you don't need any sophisticated mechanism to reference to your
objects.

2. Answer of your question: Use get().

Uwe Ligges
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list