[R] How to stack the columns of matrix
Bill.Venables@cmis.csiro.au
Bill.Venables at cmis.csiro.au
Wed Jun 12 15:46:17 CEST 2002
Peter Schlattman asks:
> -----Original Message-----
> From: Dr. Peter Schlattmann
> [mailto:schlatti at mailer.ukbf.fu-berlin.de]
> Sent: Wednesday, June 12, 2002 11:37 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] How to stack the columns of matrix
>
> Dear all,
>
> I need to stack the columns of a matrix with a variable number of columns.
> I am aware of
>
> new<-c(a[,1],a[,2])
>
> 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?
[WNV] In a sense they are already 'stacked', as you put it, in a
sense.
X[i, j] refers to the matrix element, X[k] refers to the kth element
of the column stacked matrix (unless k itself is a matrix, but that is
another story).
To make it official with no going back you could use either
new <- as.vector(a)
new <- a; dim(new) <- NULL
or a variety of other dodges. After either of these new is the
stacked version of a.
Bill Venables.
> Many thanks in advance
> Peter
>
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
> -.-.-
> 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
mailing list