[R] Question about simulation design...

Greg Snow Greg.Snow at imail.org
Mon Nov 16 23:08:45 CET 2009


You should be able to do this effectively in 1 line:

> my.data <- lapply( paste( 'data', 1:N, '.dat', sep='' ), read.table )

Then everything is in my.data, if you want them named then do a second line:

> names(my.data) <- paste( 'data', 1:N, '.dat', sep='' )

Doing the same analysis on each dataset can now be done using lapply or sapply.


-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Jeff Harring
> Sent: Thursday, November 12, 2009 6:22 AM
> To: r-help at r-project.org
> Subject: [R] Question about simulation design...
> 
> 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
> 
> --
> **********************************************************
> Jeffrey R. Harring, Assistant Professor
> Department of Measurement, Statistics & Evaluation (EDMS)
> 1230 Benjamin Building
> University of Maryland
> College Park, MD 20742-1115
> 
> Phone: 	301.405.3630
> Fax: 	301.314.9245
> Email: 	harring at umd.edu
> Web:  	http://www.education.umd.edu/EDMS/fac/Harring/webpage.html
> 
> ______________________________________________
> 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