[R] Batch Import

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Thu Mar 29 22:54:33 CEST 2001


tod.strugnell at yale.edu writes:

> I  would like to batch import a series of files. Every imported file
> will get the same prefix followed by a digit corresponding to it's
> identity (prefix.1, prefix.2, prefix.3, etc).
> 
> the general structure I assume would be something like:
> 
> for (i in 1:i) {
>         prefix.i <- function("data", i)
> }
> 
> At present I have not found any pointers/methods on how to accomplish
> this. The
> methods I have tried end up writing the new data overtop of the old
> using the same filename.  Any suggestions or resources that I have
> missed or should refer to would be appreciated.

You can do it with a construction of the form

assign(paste("prefix",i,sep=""), func("data", i))

if you want, but I don't think that's what you want. More likely you'd
really want a higher-level structure to hold the values, e.g.

prefix <- lapply(1:n, function(i) func("data", i))

would give you the structures as prefix$1, prefix$2, ....
(or prefix[[1]], prefix[[2]], ...)

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list