[R] How to stack the columns of matrix
alobo at paleo.ija.csic.es
Wed Jun 12 17:47:54 CEST 2002
If you have no idea of the max. number of cols, then
a <- NULL
each time you have a new vector to add:
a <- cbind(a,newvector)
If you can have some idea of the maximum number of cols.,
it seems that it's more efficient for the memory to create
a <- matrix(0,nrow=nr, ncol=maxcol)
newcolnumber <- newcolnumber + 1
#having newcolnumber <- 0 at the begining of the function
a[,newcolnumber] <- newvector
A the end, keep only those cols that have been used
(the last value of newcolnumber):
On Wed, 12 Jun 2002, Dr. Peter Schlattmann wrote:
> Dear all,
> I need to stack the columns of a matrix with a variable number of columns.
> I am aware of
> if I have a matrix 'a' with e.g. two columns. For a simulation study I
> need to stack
> the matrix with a variable number of columns. Is there a way to do this?
> Many thanks in advance
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
More information about the R-help