Hello, I am trying to create a data frame with a unique name, based on indexing of for loop. I was wondering if there is a way to do this, I keep running into errors when I try to do this. Below is a brief example, I am trying to get two data frames (name1 and name2). Any suggestions are appreciated. Thanks, Doug # Example for (i in 1:2) { x=c(1,2,3,4) y=c(10,20,30,40) G <- paste("name", i, sep="") G[i] <- data.frame(x,y) } -- --------------------------------- Douglas M. Hultstrand, MS Senior Hydrometeorologist Metstat, Inc. Windsor, Colorado voice: 720.771.5840 email: dmhultst at metstat.com web: http://www.metstat.com
\Why not put all the data frames in a list? Kjetil On Wed, Jun 23, 2010 at 6:56 PM, Douglas M. Hultstrand <dmhultst at metstat.com> wrote:> Hello, > > I am trying to create a data frame with a unique name, based on indexing of > for loop. ?I was wondering if there is a way to do this, I keep running into > errors when I try to do this. ?Below is a brief example, I am trying to get > two data frames (name1 and name2). > > Any suggestions are appreciated. > > Thanks, > Doug > > # Example > for (i in 1:2) { > ? ? ? x=c(1,2,3,4) > ? ? ? y=c(10,20,30,40) > ? ? ? G <- paste("name", i, sep="") > ? ? ? G[i] <- data.frame(x,y) > } > > -- > --------------------------------- > Douglas M. Hultstrand, MS > Senior Hydrometeorologist > Metstat, Inc. Windsor, Colorado > voice: 720.771.5840 > email: dmhultst at metstat.com > web: http://www.metstat.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. >
Hi: Try this:> for (i in 1:2) {+ x=c(1,2,3,4) + y=c(10,20,30,40) + G <- paste("name", i, sep="") + assign(G, data.frame(x,y)) + }> name1x y 1 1 10 2 2 20 3 3 30 4 4 40> name2x y 1 1 10 2 2 20 3 3 30 4 4 40 HTH, Dennis On Wed, Jun 23, 2010 at 3:56 PM, Douglas M. Hultstrand <dmhultst@metstat.com> wrote:> Hello, > > I am trying to create a data frame with a unique name, based on indexing of > for loop. I was wondering if there is a way to do this, I keep running into > errors when I try to do this. Below is a brief example, I am trying to get > two data frames (name1 and name2). > > Any suggestions are appreciated. > > Thanks, > Doug > > # Example > for (i in 1:2) { > x=c(1,2,3,4) > y=c(10,20,30,40) > G <- paste("name", i, sep="") > G[i] <- data.frame(x,y) > } > > -- > --------------------------------- > Douglas M. Hultstrand, MS > Senior Hydrometeorologist > Metstat, Inc. Windsor, Colorado > voice: 720.771.5840 > email: dmhultst@metstat.com > web: http://www.metstat.com > > ______________________________________________ > R-help@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. >[[alternative HTML version deleted]]