[R] Generating Data Sets -- Each with a Different Name

Spencer Graves spencer.graves at pdf.com
Fri Oct 24 00:24:20 CEST 2003


      Have you considered using "paste(..., sep="") to generate either 
the object names or file names you want? 

      If you want objects in R, have you considered "assign"?  If you 
want files, then have you considered "write"? 

      hope this helps. 
      spencer graves

Ken Kelley wrote:

> Hello all.
>
> I was wondering if anyone had insight into how I might generate a 
> large number of data sets/vectors, where each of the data sets/vectors 
> have a different name?
>
> For example, suppose I wanted to generate N data sets/vectors, each 
> with a different name such as:
>
> Random.Data.1 <- rnorm(10, 0, 1)
> Random.Data.2 <- rnorm(10, 0, 1)
> Random.Data.3 <- rnorm(10, 0, 1)
>     .        .   
>     .        .
>     .        .
> Random.Data.N <- rnorm(10, 0, 1)
>
> Because I don't want to name each data set/vector myself, I want some 
> sort of looping/automatic procedure to do it for me. However, I'm not 
> sure how to do this.
>
> What I want is something conceptually analogous to the following:
>
> for(i in 1:N)
> {
> Random.Data.i <- rnorm(10, 0, 1)
> }
>
> Note the "i" in the "Random.Data.i" vector. This is the value I want 
> to change for each iteration of the loop, so that I can have N data 
> sets/vectors automatically generated for me with different names.
>
> Does anyone know of a method where I can accomplish such a procedure.
> Thanks for your thoughts,
> Ken
>
> P.S. For those of you wondering why I would ever want to do such a 
> thing, it is because I need a large number of data sets to use in a 
> Monte Carlo study with specialized software. If I could do the 
> simulation all is R, then obviously I could loop the whole procedure. 
> The program I am using has a limited Monte Carlo facility where each 
> of the (say 10,000) data sets must be generated elsewhere.
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help




More information about the R-help mailing list