[R] how to create automatically names for vectors in a loop?

Lukas Schefczyk Rlist at mschefczyk.de
Fri May 28 05:05:51 CEST 2010


Hallo,

x=1

while (x<100)

 {
   vectorx<- rnorm(100)
    assign(paste("vector",x,sep=""),vectorx)
x=x+1

}
ls()

HTH
Lukas Schefczyk

--------------------------------------------------
From: "Zoppoli, Gabriele (NIH/NCI) [G]" <zoppolig at mail.nih.gov>
Sent: Friday, May 28, 2010 4:43 AM
To: <r-help at r-project.org>
Subject: [R] how to create automatically names for vectors in a loop?

> Hi,
>
> I want to generate a number of vectors and store them with different 
> names, like this:
>
> x=1
>
> while (x<100)
>
> {
>   vector#x# = rnorm(100)
>   x=x+1
> }
>
> where each vector has, at its hand, instead of #x# a number which goes 
> from 1 to 99.
>
> How can I do this?
>
> Thanks
>
> Gabriele Zoppoli, MD
> Ph.D. Fellow, Experimental and Clinical Oncology and Hematology, 
> University of Genova, Genova, Italy
> Guest Researcher, LMP, NCI, NIH, Bethesda MD
>
> Work: 301-451-8575
> Mobile: 301-204-5642
> Email: zoppolig at mail.nih.gov
> ______________________________________________
> R-help at r-project.org 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