[R] binding rows from different matrices
Giovanni Petris
GPetris at uark.edu
Tue Jun 29 20:11:11 CEST 2004
Still another variation on the same theme:
> matrix(t(cbind(veca,vecb,vecc)),nc=5,byrow=T)
Giovanni
> Date: Tue, 29 Jun 2004 17:58:32 +0200
> From: Peter Dalgaard <p.dalgaard at biostat.ku.dk>
> Sender: r-help-bounces at stat.math.ethz.ch
> Cc: r-help at stat.math.ethz.ch, Stephane DRAY <stephane.dray at umontreal.ca>
> Precedence: list
> User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2
> Lines: 20
>
> Prof Brian Ripley <ripley at stats.ox.ac.uk> writes:
>
> > You can almost always index in such problems: here is one way.
> >
> > rbind(veca,vecb,vecc)[matrix(1:15, 3, byrow=T), ]
> >
> > Take it apart of see how it works, if it is not immediately obvious.
>
> Or, a little longer, but perhaps more intuitive:
>
> matrix(aperm(array(c(veca,vecb,vecc),c(5,5,3)),c(3,1,2)),15)
>
> I.e., convert to array, do generalized transpose, convert back to
> matrix. Not that I got the index calculations right on first try....
>
> --
> O__ ---- Peter Dalgaard Blegdamsvej 3
> c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
> (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
> ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>
--
__________________________________________________
[ ]
[ Giovanni Petris GPetris at uark.edu ]
[ Department of Mathematical Sciences ]
[ University of Arkansas - Fayetteville, AR 72701 ]
[ Ph: (479) 575-6324, 575-8630 (fax) ]
[ http://definetti.uark.edu/~gpetris/ ]
[__________________________________________________]
More information about the R-help
mailing list