[R] creation of objects

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Jan 22 16:51:36 CET 2002


On Tue, 22 Jan 2002, Patrick Buetzberger wrote:

> Hi there,
>
> I'm a new R user and I've got a little problem:
> I would like to read several files at once (which works) and create R
> objects for each individual file (which doesen't work) within a loop:
> this is the way I've tried to program this:
>
> fn<-list.files(path =
> "/home/klimet/patrick/LAEGEREN/NEBEL/FOGEVENT2000/", pattern=NULL,
> all.files=FALSE, full.names=FALSE)
> for(i in seq(1,nfn,1)){
>
> fin<-paste("/home/klimet/patrick/LAEGEREN/NEBEL/FOGEVENT2000/",fn[i],sep="")
>
>     fi <- as.matrix(read.table(fin,skip=1))
> }
>
> The i in fin and fi should create new objects for every loop with i
> being the number, like f1, f2,f3 and so  on. The way I did it, it reads
> i as a character and overwrites the object in every loop.
>
> Thanks for any hints....

?assign, something like

assign(paste("f", i, sep = ""), as.matrix(read.table(fin,skip=1)))

Overwriting fn seems fine to me.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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