Skip to content

Question about simulation design...

3 messages · Jeff Harring, Peter Alspach, Greg Snow

#
Help R list servers,

I have 500 external data sets for a simulation study that I would like 
to bring into R to analyze. They have the names data1.dat, data2.dat, 
..., dataN.dat

Is there a way to automatize the bringing in of these data sets in R 
using the read.table function within a looping cycle?

For example...

for (j in 1:N){
data_"j" = read.table("data"j".dat, header=F)

executable code
.
.
.
}

bring in the next data set.

SAS uses a ampersand "&" to automatize the process.

Example code:

data _NULL_;
    set final;
        filename out "C:\data&k..dat";
        file out;
        put variables;
run;

I would welcome any insight into how to address this issue.

Thank you.
Jeff Harring
#
Tena koe Jeff

Try something like:

for (i in 1:n)
{
  assign(paste('data', i, sep=''), read.table(paste('data', i, '.dat',
sep=''), header=F)) 
  .
  .
  .
}

HTH ....

Peter Alspach
4 days later
#
You should be able to do this effectively in 1 line:
Then everything is in my.data, if you want them named then do a second line:
Doing the same analysis on each dataset can now be done using lapply or sapply.