title: How to save simulation data using for loop in R
body: <p>I am simulating several data sets using for loop in R and saving the data sets in text files in a folder. Since I need to analyze these data sets, I am importing these data from the folder to R and doing my analyses. I am wondering if there is any way to do both simulation and analysis by keeping them in R as data frames instead of saving and importing. Here is my code:</p>
  
  <pre><code>setwd("C:\\Users\\John\\Desktop\\datageneration")
  
  kitem&lt;-10
  N&lt;-100
  disc&lt;-rnorm(k,0,1)
  diff=rnorm(k,0,1)
  
  irtp&lt;-function(t,a,b,pexp)
  {
      pexp&lt;-1/(1+exp(-b*(t-a)))
      pexp
  }
  for( iter in 1:20) 
  {
      X&lt;-mat.or.vec(N,kitem)
      P&lt;-mat.or.vec(N,kitem)
      for(i in 1:N)
      {
          theta&lt;-rnorm(N,0,1)
          assign(paste0("theta", iter), theta)
          filename1 &lt;- paste (" theta",iter ,".txt ", sep ="")
          write.table( get(paste0("theta",iter)) , file = filename1 , row.names =FALSE ,col.names = FALSE )
          for(k in 1:kitem)
          {
              P[i,k]&lt;-irtp(theta[i],diff[k],disc[k],pexp)
              X[i,k]&lt;-ifelse(runif(1)&lt;P[i,k],1,0)
              assign(paste0("X",iter), X)         # HERE'S THE PART THAT I NEED HELP
              filename2 &lt;- paste ("X",iter ,".txt ", sep ="")
              write.table( get(paste0("X",iter)) , file = filename2 , row.names =FALSE ,col.names = FALSE )
          }
      }
  }
  </code></pre>
  
  <p>All I want to do is just to use the generated data files (e.g., theta1, theta2, theta3..., theta20) by calling their names(e.g., theta1). Since I am generating thousands of data sets, I would like to know if I can do it without using write.table then read.table functions. I will be very appreciated if you can help me.</p>