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.
Spencer Graves
2003-Oct-23 22:24 UTC
[R] Generating Data Sets -- Each with a Different Name
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
apjaworski@mmm.com
2003-Oct-23 22:47 UTC
[R] Generating Data Sets -- Each with a Different Name
You need paste and assign functions. Paste will create a sequence of names and assign will give values to the variables with these names. This modification of your loop should work for(i in 1:N) { assign(paste("Random.Data.", i, sep=''), rnorm(10, 0, 1)) } Cheers, Andy __________________________________ Andy Jaworski Engineering Systems Technology Center 3M Center, 518-1-01 St. Paul, MN 55144-1000 ----- E-mail: apjaworski at mmm.com Tel: (651) 733-6092 Fax: (651) 736-3122 |---------+--------------------------------> | | Ken Kelley | | | <KKelley at nd.edu> | | | Sent by: | | | r-help-bounces at stat.m| | | ath.ethz.ch | | | | | | | | | 10/23/2003 17:09 | | | | |---------+--------------------------------> >-----------------------------------------------------------------------------------------------------------------------------| | | | To: r-help at stat.math.ethz.ch | | cc: | | Subject: [R] Generating Data Sets -- Each with a Different Name | >-----------------------------------------------------------------------------------------------------------------------------| 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
Apparently Analagous Threads
- Individual log likelihoods of nlsList objects.
- Generating unordered, with replacement, samples
- Draw values from multiple data sets as inputs to a Monte-Carlo function; then apply across entire matrix
- Publication & Project: Verificarlo: checking floating point accuracy through Monte Carlo Arithmetic
- Conditional CCA and Monte Carlo - Help!