Write a R program to rotate a given matrix 90 degree clockwise rotation.
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
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
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 7need an explanation for this answer? contact us directly to get an explanation for this answer