Re: [R] growing dataframes with rbind

2009-02-24 Thread Jorge Ivan Velez
Dear all, Here is one more way to go though using rep() and then matrix(): > rows <- 1:3 > matrix(rep(rows,5),ncol=5) [,1] [,2] [,3] [,4] [,5] [1,]11111 [2,]22222 [3,]33333 HTH, Jorge On Tue, Feb 24, 2009 at 1:43 PM, Gabor Grothe

Re: [R] growing dataframes with rbind

2009-02-24 Thread Gabor Grothendieck
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,]11111 [2,]22222 [3,]333

Re: [R] growing dataframes with rbind

2009-02-24 Thread Greg Snow
If you know the final size that your matrix will be, it is better to preallocate the matrix, then insert the rows into the matrix: mymat <- matrix( nrow=100, ncol=10 ) for( i in 1:100 ){ mymat[i, ] <- rnorm(10) } Even better than this is to use replicate or sapply if you can, they will t