Dear fellows, I am a novice in R. I would like to combine a matrix and a vector. Assume that we have the matrix a and the vector b with same length of column. a<-matrix(seq(1:10),nrow=2,ncol=5,byrow=TRUE) a1 2 3 4 5 6 7 8 9 10 b<-t(c(11,12,13,14,15)) b11 12 13 14 15 Then, I want to combine a and b as follows. c1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 If you teach me to easily combine the matrix and the vector, I will greatly appreciate you. Thank you. Regards, Wonsang ----- -- Wonsang You Special Lab Non-Invasive Brain Imaging Leibniz Institute for Neurobiology http://www.ifn-magdeburg.de -- View this message in context: http://r.789695.n4.nabble.com/How-to-combine-matrix-and-vector-tp2541797p2541797.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]
Hi! Take a look at rbind() Btw, I don't think you have to transpose b. HTH, Ivan Le 9/16/2010 11:09, Wonsang You a écrit :> Dear fellows, > > I am a novice in R. I would like to combine a matrix and a vector. Assume > that we have the matrix a and the vector b with same length of column. > > a<-matrix(seq(1:10),nrow=2,ncol=5,byrow=TRUE) > a> 1 2 3 4 5 > 6 7 8 9 10 > > b<-t(c(11,12,13,14,15)) > b> 11 12 13 14 15 > > Then, I want to combine a and b as follows. > > c> 1 2 3 4 5 > 6 7 8 9 10 > 11 12 13 14 15 > > If you teach me to easily combine the matrix and the vector, I will greatly > appreciate you. Thank you. > > Regards, > Wonsang > > > ----- > -- > Wonsang You > Special Lab Non-Invasive Brain Imaging > Leibniz Institute for Neurobiology > http://www.ifn-magdeburg.de-- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calandra@uni-hamburg.de ********** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php [[alternative HTML version deleted]]
Thank you so much for your help. It was successful to combine matrix and vector by using "rbind" as follows.> a<-matrix(seq(1:10),nrow=2,ncol=5,byrow=TRUE) > a[,1] [,2] [,3] [,4] [,5] [1,] 1 2 3 4 5 [2,] 6 7 8 9 10> b<-t(c(11,12,13,14,15)) > b[,1] [,2] [,3] [,4] [,5] [1,] 11 12 13 14 15> rbind(a,b)[,1] [,2] [,3] [,4] [,5] [1,] 1 2 3 4 5 [2,] 6 7 8 9 10 [3,] 11 12 13 14 15 ----- -- Wonsang You Special Lab Non-Invasive Brain Imaging Leibniz Institute for Neurobiology http://www.ifn-magdeburg.de -- View this message in context: http://r.789695.n4.nabble.com/How-to-combine-matrix-and-vector-tp2541797p2542362.html Sent from the R help mailing list archive at Nabble.com.
Seemingly Similar Threads
- How to uncompress a gz file in R
- How to Adaptively Set Up the Coordinate Range of Multiple Graphs in One Figure
- How to fix error in the package 'rgenoud'
- Fast Two-Dimensional Optimization
- Simulation of Multivariate Fractional Gaussian Noise and Fractional Brownian Motion