Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

x =  matrix(1:9, 3)
print("Original matrix:")
print(x)
rotate = t(apply(x, 2, rev))
print("Rotate the said matrix 90 degree clockwise:")
print(rotate)

Sample Output:

[1] "Original matrix:"
     [,1] [,2] [,3]
[1,]    1    4    7
[2,]    2    5    8
[3,]    3    6    9
[1] "Rotate the said matrix 90 degree clockwise:"
     [,1] [,2] [,3]
[1,]    3    2    1
[2,]    6    5    4
[3,]    9    8    7

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now