+ 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?
3 odpowiedzi
+ 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!
+ 2
Kishalaya, it worked.
Thanks very much
0
Awesome! Cheers! 😊👍