tedzzx
2008-Oct-24 08:36 UTC
[R] how to simply the procedure of creating a group of data.frame?
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 -- View this message in context: http://www.nabble.com/how-to-simply-the-procedure-of-creating-a-group-of-data.frame--tp20146344p20146344.html Sent from the R help mailing list archive at Nabble.com.
Dimitris Rizopoulos
2008-Oct-24 09:13 UTC
[R] how to simply the procedure of creating a group of data.frame?
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
markleeds at verizon.net
2008-Oct-24 09:20 UTC
[R] how to simply the procedure of creating a group of data.frame?
if you do below, then d[[1]] is the first, d[[2]] is the second etc. d <- lapply(1:50,function(.index) { data.frame(x=factor(),y=numeric()) }) print(d) print(str(d)) On Fri, Oct 24, 2008 at 4:36 AM, 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 > -- > View this message in context: > http://www.nabble.com/how-to-simply-the-procedure-of-creating-a-group-of-data.frame--tp20146344p20146344.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.