[R] how to simply the procedure of creating a group of data.frame?
Dimitris Rizopoulos
d.rizopoulos at erasmusmc.nl
Fri Oct 24 11:13:42 CEST 2008
one way is the following:
for (i in 1:50) {
dd <- data.frame(x = gl(2, 1), y = rnorm(2))
assign(paste("d", i, sep = ""), dd)
}
However, I would suggest to put all these data.frames in list, e.g.,
df.list <- lapply(1:50, function (i) data.frame(x = gl(2, 1), y = rnorm(2)))
names(df.list) <- paste("d", seq_along(df.list), sep = "")
I hope it helps.
Best,
Dimitris
tedzzx wrote:
> Dear R users,
>
> I want to creat a group of data frames, such as:
> d1<-data.frame(x=factor(),y=numeric(),...)
> d2<-data.frame(x=factor(),y=numeric(),...)
> d3<-data.frame(x=factor(),y=numeric(),...)
> :
> :
> d50<-data.frame(x=factor(),y=numeric())
>
> How can I use the loop to simply my procedure?
> Thanks advance
>
> Ted
--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus Medical Center
Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
More information about the R-help
mailing list