I have a series of data frames that are identical structurally, i.e. - made with the same code, but I need to add them together so that they become one, longer, data frame, i.e. - each of the slot vectors are increased in length by the length of the added data frame vectors. So if I have df1 with a slot A so that length(df1$A) = 100 and I have df2 with a slot A so that length(df2$A)=200 then I need a method to create df3 its slot A is the df1$A plus df2$A such that length(df3$A) 300. It does not appear that if you use data.frame to join two data frames it just adds the slots of both sources to the destination data frame and that is not what I want. In my finally solution, I need to do this with multiple data.frames that slot-wise are identical, but each slot length is different between data frames. Seems like there should be an easy solution, but I just have not stumbled across it in the documentation. Thanks, John C. Sweval Database Architect Illumigen Biosciences, Inc. Email: jsweval@illumigen.com Phone: 206-378-0400 Fax: 206-378-0408 [[alternative HTML version deleted]]
Use rbind() (for row-bind). Here are some examples:> d1 <- data.frame(x=1, y=1) > d2 <- data.frame(x=1:2, y=1:2) > d3 <- data.frame(x=3, y=3) > rbind(d1,d2,d3)x y 1 1 1 11 1 1 2 2 2 12 3 3> do.call("rbind", list(d1,d2,d3))x y 1 1 1 11 1 1 2 2 2 12 3 3 [or even this:]> do.call("rbind", eval(parse(text=paste(paste("list(",paste("d",1:3,sep="",collapse=","), ")"))))) x y 1 1 1 11 1 1 2 2 2 12 3 3 HTH, Andy> From: John Sweval > > I have a series of data frames that are identical structurally, i.e. - > made with the same code, but I need to add them together so that they > become one, longer, data frame, i.e. - each of the slot vectors are > increased in length by the length of the added data frame vectors. > > So if I have df1 with a slot A so that length(df1$A) = 100 and I have > df2 with a slot A so that length(df2$A)=200 then I need a method to > create df3 its slot A is the df1$A plus df2$A such that > length(df3$A) > 300. > > It does not appear that if you use data.frame to join two > data frames it > just adds the slots of both sources to the destination data frame and > that is not what I want. > > In my finally solution, I need to do this with multiple > data.frames that > slot-wise are identical, but each slot length is different > between data > frames. > > Seems like there should be an easy solution, but I just have not > stumbled across it in the documentation. > > Thanks, > John C. Sweval > Database Architect > Illumigen Biosciences, Inc. > Email: jsweval at illumigen.com > Phone: 206-378-0400 > Fax: 206-378-0408 > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments,...{{dropped}}
John - The function rbind() operates on pairs of data frames, and (somewhat arcane and definitely NOT for beginning users) do.call("rbind", list(df1, df2, df3, df4, df5))) will combine any number (in this case 5) of data frames. As of February 2003, the do.call() approach did not deal gracefully with columns in a data frame which had been converted to factors (happens by default in read.table()). In my own code I had to go through some gyrations to protect against that. For futher information on the do.call() approach, search the r-help archives for "do.call" AND "rbind". In particular, there was a thread involving jerosenb and rpeng titled "[R] quotes within quotes" with one email dated Wed, 9 Apr 2003. - tom blackwell - u michigan medical school - ann arbor - On Tue, 9 Mar 2004, John Sweval wrote:> I have a series of data frames that are identical structurally, i.e. - > made with the same code, but I need to add them together so that they > become one, longer, data frame, i.e. - each of the slot vectors are > increased in length by the length of the added data frame vectors. > > So if I have df1 with a slot A so that length(df1$A) = 100 and I have > df2 with a slot A so that length(df2$A)=200 then I need a method to > create df3 its slot A is the df1$A plus df2$A such that length(df3$A) > 300. > > It does not appear that if you use data.frame to join two data frames it > just adds the slots of both sources to the destination data frame and > that is not what I want. > > In my finally solution, I need to do this with multiple data.frames that > slot-wise are identical, but each slot length is different between data > frames. > > Seems like there should be an easy solution, but I just have not > stumbled across it in the documentation. > > Thanks, > John C. Sweval > Database Architect > Illumigen Biosciences, Inc. > Email: jsweval at illumigen.com > Phone: 206-378-0400 > Fax: 206-378-0408 >
Correction to my reply below: If my memory serves correctly, one year and many projects later, I wanted to keep character data as character, not factors, throughout. The gyrations were to maintain this despite using rbind(), not because rbind() behaved badly with factors. Please excuse my foggy memory. - tom blackwell - u michigan medical school - ann arbor - On Tue, 9 Mar 2004, Tom Blackwell wrote:> John - > > The function rbind() operates on pairs of data frames, and > (somewhat arcane and definitely NOT for beginning users) > > do.call("rbind", list(df1, df2, df3, df4, df5))) > > will combine any number (in this case 5) of data frames. > > As of February 2003, the do.call() approach did not deal > gracefully with columns in a data frame which had been > converted to factors (happens by default in read.table()). > In my own code I had to go through some gyrations to protect > against that. > > For futher information on the do.call() approach, search > the r-help archives for "do.call" AND "rbind". In particular, > there was a thread involving jerosenb and rpeng titled > "[R] quotes within quotes" with one email dated Wed, 9 Apr 2003. > > - tom blackwell - u michigan medical school - ann arbor - > > On Tue, 9 Mar 2004, John Sweval wrote: > > > I have a series of data frames that are identical structurally, i.e. - > > made with the same code, but I need to add them together so that they > > become one, longer, data frame, i.e. - each of the slot vectors are > > increased in length by the length of the added data frame vectors. > > > > So if I have df1 with a slot A so that length(df1$A) = 100 and I have > > df2 with a slot A so that length(df2$A)=200 then I need a method to > > create df3 its slot A is the df1$A plus df2$A such that length(df3$A) > > 300. > > > > It does not appear that if you use data.frame to join two data frames it > > just adds the slots of both sources to the destination data frame and > > that is not what I want. > > > > In my finally solution, I need to do this with multiple data.frames that > > slot-wise are identical, but each slot length is different between data > > frames. > > > > Seems like there should be an easy solution, but I just have not > > stumbled across it in the documentation. > > > > Thanks, > > John C. Sweval > > Database Architect > > Illumigen Biosciences, Inc. > > Email: jsweval at illumigen.com > > Phone: 206-378-0400 > > Fax: 206-378-0408 > > > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
On 9 Mar 2004 at 14:41, John Sweval wrote: If you have the dataframes as components of a list dfs, maybe you can do something like do.call("cbind", dfs) Kjetil Halvorsen> I have a series of data frames that are identical structurally, i.e. - > made with the same code, but I need to add them together so that they > become one, longer, data frame, i.e. - each of the slot vectors are > increased in length by the length of the added data frame vectors. > > So if I have df1 with a slot A so that length(df1$A) = 100 and I have > df2 with a slot A so that length(df2$A)=200 then I need a method to > create df3 its slot A is the df1$A plus df2$A such that length(df3$A) > = 300. > > It does not appear that if you use data.frame to join two data frames > it just adds the slots of both sources to the destination data frame > and that is not what I want. > > In my finally solution, I need to do this with multiple data.frames > that slot-wise are identical, but each slot length is different > between data frames. > > Seems like there should be an easy solution, but I just have not > stumbled across it in the documentation. > > Thanks, > John C. Sweval > Database Architect > Illumigen Biosciences, Inc. > Email: jsweval at illumigen.com > Phone: 206-378-0400 > Fax: 206-378-0408 > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html
check rbind Joris John Sweval wrote:>I have a series of data frames that are identical structurally, i.e. - >made with the same code, but I need to add them together so that they >become one, longer, data frame, i.e. - each of the slot vectors are >increased in length by the length of the added data frame vectors. > >So if I have df1 with a slot A so that length(df1$A) = 100 and I have >df2 with a slot A so that length(df2$A)=200 then I need a method to >create df3 its slot A is the df1$A plus df2$A such that length(df3$A) >300. > >It does not appear that if you use data.frame to join two data frames it >just adds the slots of both sources to the destination data frame and >that is not what I want. > >In my finally solution, I need to do this with multiple data.frames that >slot-wise are identical, but each slot length is different between data >frames. > >Seems like there should be an easy solution, but I just have not >stumbled across it in the documentation. > >Thanks, >John C. Sweval > Database Architect > Illumigen Biosciences, Inc. > Email: jsweval at illumigen.com > Phone: 206-378-0400 > Fax: 206-378-0408 > > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://www.stat.math.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > >-- ====================================================================== Joris De Wolf CropDesign N.V. Plant Evaluation Group Technologiepark 3 B-9052 Zwijnaarde Belgium Tel. : +32 9 242 91 55 Fax : +32 9 241 91 73 ====================================================================== confidentiality notice: The information contained in this e-mail is confidential and...{{dropped}}
Apparently Analagous Threads
- 64-bit Windows 2003 build of R
- Best way/practice to create a new data frame from two given ones with last column computed from the two data frames?
- merging several dataframes from a list
- Looping through a list of objects & do something...
- Multiple merge, better solution?