[R] growing dataframes with rbind

Gabor Grothendieck ggrothendieck at gmail.com
Tue Feb 24 19:43:08 CET 2009


Suppose we want 3 rows and the ith row should have 5 columns of i.
Create a list whose ith component is the ith row and rbind them:

> rows <- 1:3
> do.call(rbind, lapply(rows, rep, 5))
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    1    1    1    1
[2,]    2    2    2    2    2
[3,]    3    3    3    3    3


On Tue, Feb 24, 2009 at 1:01 PM, Alexy Khrabrov <deliverable at gmail.com> wrote:
> I'm growing a large dataframe by composing new rows and then doing
>
> row <- compute.new.row.somehow(...)
> d <- rbind(d,row)
>
> Is this a fast/preferred way?
> Cheers,
> Alexy
>
> ______________________________________________
> 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.
>




More information about the R-help mailing list