+ 2

Creating a Matrix in R from existing rows of other matrices

I have two matrices which I created with the code A<- matrix(9:1, nrow=3) and B<- matrix ( diag 1:3, nrow=3) . Now, I would like to creat a new matrix, C, by extracting first two rows of A and third row of B. What code do I use?

30th Oct 2018, 2:22 AM
Symon
Symon - avatar
3 ответов
+ 4
My R is a bit rusty, and I cannot test this on Sololearn. So please let me know if this doesn't work. A <- matrix(9:1, nrow=3) B <- diag(1:3, nrow=3) C <- rbind(A[1:2,], B[3,]) Thanks!
30th Oct 2018, 7:13 AM
Kishalaya Saha
Kishalaya Saha - avatar
+ 2
Kishalaya, it worked. Thanks very much
30th Oct 2018, 8:37 AM
Symon
Symon - avatar
0
Awesome! Cheers! 😊👍
30th Oct 2018, 8:49 AM
Kishalaya Saha
Kishalaya Saha - avatar