[R] using dynamic variable names

Rolf Turner rolf.turner at xtra.co.nz
Thu Oct 13 10:09:12 CEST 2011


(1) See ?paste, ?assign, and ?get.

(2) ***Don't*** do it this way!!!  Use a list instead.  That's the R-ish
way of doing things.  See ?list.

     cheers,

         Rolf Turner

On 13/10/11 18:23, Sasso Kocovski wrote:
> Hi, hopefully you can help me out - thanks in advance.
>
> I would like to assign variable (or vectors) names dynamically, hence, after
> you assign the number of new vectors then they populate for use later in the
> algorithm.  Below is an example:
>
> n<-5
> for (i in (1:n)) {
> vector_i<- c(1:10)
> }
>
> Here what I am trying to do is create n=5 vectors (vector_1, vector_2,
> vector_3, vector_4, vector_5) that I will use later in my algorithm.  I
> don't want to create a matrix because I will use these in a time series
> later and the vectors will be of different length, where having '0' will
> produce wrong results.  This may not be possible in R, if so you can also
> save me time of trying to figure this out on my own.



More information about the R-help mailing list