Write a R program to convert a given matrix to a 1 dimensional array.
m=matrix(1:12,3,4) print("Original matrix:") print(m) a = as.vector(m) print("1 dimensional array:") print(a)
Sample Output:
[1] "Original matrix:" [,1] [,2] [,3] [,4] [1,] 1 4 7 10 [2,] 2 5 8 11 [3,] 3 6 9 12 [1] "1 dimensional array:" [1] 1 2 3 4 5 6 7 8 9 10 11 12
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] [,4] [1,] 1 4 7 10 [2,] 2 5 8 11 [3,] 3 6 9 12 [1] "1 dimensional array:" [1] 1 2 3 4 5 6 7 8 9 10 11 12need an explanation for this answer? contact us directly to get an explanation for this answer