w3resource

R Programming: Concatenate two given matrixes of same column but different rows

R Programming: Matrix Exercise-13 with Solution

Write a R program to concatenate two given matrixes of same column but different rows.

Sample Solution:

R Programming Code:

x = matrix(1:12, ncol=3)
y = matrix(13:24, ncol=3)
print("Matrix-1")
print(x)
print("Matrix-2")
print(y)
result = dim(rbind(x,y))
print("After concatenating two given matrices:")
print(result)

Sample Output:

[1] "Matrix-1"
     [,1] [,2] [,3]
[1,]    1    5    9
[2,]    2    6   10
[3,]    3    7   11
[4,]    4    8   12
[1] "Matrix-2"
     [,1] [,2] [,3]
[1,]   13   17   21
[2,]   14   18   22
[3,]   15   19   23
[4,]   16   20   24
[1] "After concatenating two given matrices:"
[1] 8 3              

R Programming Code Editor:



Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a R program to rotate a given matrix 90 degree clockwise rotation.

Test your Programming skills with w3resource's quiz.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.