[R] (no subject)

Uwe Ligges ligges at statistik.uni-dortmund.de
Thu Dec 5 13:59:02 CET 2002


Jan Wiener wrote:
> 
> hi,
> suppose you have a for-loop like this:
> 
> for(i in1:x) {} ...
> 
> now you want to generate a variable in every
> cycle (since you do not know the size of x in
> beforehand you have to do this dynamically).
> 
> the variable should e.g. look like this:
> variableName1<-c() (if x==1)
> variableName2<-c() (ifx==2)
> variableName3<-c() (if x==3)
> ..
> ..
> i tried this(which obviously didn't work):
> 
> paste("variableName",x,sep="")<-c(2,3,4)
> 
> so i need
> something similiar to this (but working!)!

- This is FAQ 7.23 (see the FAQ's, please).
- I'd suggest to use a list instead of a couple of different objects.
- See ?assign for more details related to your question:
  assign(paste("variableName", x, sep=""), c(2,3,4))

Uwe Ligges




More information about the R-help mailing list