Re: [R] Concatenating data frame
And adding to Jim's solution, you may be able to further improve the speed of your code by pre-allocating the list size i.e result <- vector("list",100) for (i in 1:100){ result[[i]] <- data.frame(id=sample(letters,1), value=i) } newDataFrame <- do.call('rbind', result) Cheers Francisco >From: "jim holtman" <[EMAIL PROTECTED]> >To: "Charles Cheung" <[EMAIL PROTECTED]> >CC: r-help@stat.math.ethz.ch >Subject: Re: [R] Concatenating data frame >Date: Wed, 10 May 2006 19:02:15 -0400 > >Put the intermediate results in a list and then use do.call: > >result <- list() >for (i in 1:100){ > result[[i]] <- data.frame(id=sample(letters,1), value=i) >} >newDataFrame <- do.call('rbind', result) > > > > >On 5/10/06, Charles Cheung <[EMAIL PROTECTED]> wrote: > > > > Hello, I have searched through the R-help archive and find that the > > easiest > > way to concatenate data records in a dataframe is to use rbind() > > > > > > I know we can do that using rbind, but it is slow when we are doing >rbind > > thousands of times to a growing list, each time adding one or two >records > > to > > the ever growing existing data because in > > > > existingRecords<-rbind(existingRecords, aNewRecordToBeAdded), > > > > I am making a copy of the data each time rbind is called! > > > > Is there a way to avoid these data copying? > > > > > > Thank you in advance! > > > > Charles > > > > __ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > > http://www.R-project.org/posting-guide.html > > > > > >-- >Jim Holtman >Cincinnati, OH >+1 513 646 9390 (Cell) >+1 513 247 0281 (Home) > >What the problem you are trying to solve? > > [[alternative HTML version deleted]] > >__ >R-help@stat.math.ethz.ch mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! >http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Concatenating data frame
Put the intermediate results in a list and then use do.call: result <- list() for (i in 1:100){ result[[i]] <- data.frame(id=sample(letters,1), value=i) } newDataFrame <- do.call('rbind', result) On 5/10/06, Charles Cheung <[EMAIL PROTECTED]> wrote: > > Hello, I have searched through the R-help archive and find that the > easiest > way to concatenate data records in a dataframe is to use rbind() > > > I know we can do that using rbind, but it is slow when we are doing rbind > thousands of times to a growing list, each time adding one or two records > to > the ever growing existing data because in > > existingRecords<-rbind(existingRecords, aNewRecordToBeAdded), > > I am making a copy of the data each time rbind is called! > > Is there a way to avoid these data copying? > > > Thank you in advance! > > Charles > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > -- Jim Holtman Cincinnati, OH +1 513 646 9390 (Cell) +1 513 247 0281 (Home) What the problem you are trying to solve? [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Concatenating data frame
Hello, I have searched through the R-help archive and find that the easiest way to concatenate data records in a dataframe is to use rbind() I know we can do that using rbind, but it is slow when we are doing rbind thousands of times to a growing list, each time adding one or two records to the ever growing existing data because in existingRecords<-rbind(existingRecords, aNewRecordToBeAdded), I am making a copy of the data each time rbind is called! Is there a way to avoid these data copying? Thank you in advance! Charles __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html