Stacking matrices

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Stacking matrices

JLucke
What is an easy way to stack a matrix multiple times?  E.g.  I have a 6x6
matrix that I need to stack vertically 154 times to get a 6*154 by 6
matrix.  I would rather not rbind(X,X,...,X) matrices.    --Joe
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Stacking matrices

Benilton Carvalho-2
how about

y = X[rep(1:nrow(X), 6), ]

?

On Mon, Mar 15, 2010 at 5:37 PM,  <[hidden email]> wrote:

> What is an easy way to stack a matrix multiple times?  E.g.  I have a 6x6
> matrix that I need to stack vertically 154 times to get a 6*154 by 6
> matrix.  I would rather not rbind(X,X,...,X) matrices.    --Joe
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Stacking matrices

Chuck Cleland
In reply to this post by JLucke
On 3/15/2010 1:37 PM, [hidden email] wrote:
> What is an easy way to stack a matrix multiple times?  E.g.  I have a 6x6
> matrix that I need to stack vertically 154 times to get a 6*154 by 6
> matrix.  I would rather not rbind(X,X,...,X) matrices.    --Joe

X <- matrix(runif(36), ncol=6)

matrix(rep(t(X), 154), ncol=6, byrow=TRUE)

> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.

--
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

______________________________________________
[hidden email] 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.