Here we are explaining how to write an R program to convert a given matrix to a one-dimensional matrix. Here we are using a built-in function as.vector() for this conversion. This method helps to converts a distributed matrix into a non-distributed vector. Also, this method helps to convert any objects into a vector.
Below are the steps used in the R program to convert a given matrix to a one-dimensional one. In this R program, we directly give the values to built-in functions. And print the function result. Here we used variables mtx,x for assigning vector values and matrix.
mtx=matrix(1:12,3,4)
print("Original matrix is:")
## [1] "Original matrix is:"
print(mtx)
## [,1] [,2] [,3] [,4]
## [1,] 1 4 7 10
## [2,] 2 5 8 11
## [3,] 3 6 9 12
x = as.vector(mtx)
print("1 dimensional array is:")
## [1] "1 dimensional array is:"
print(x)
## [1] 1 2 3 4 5 6 7 8 9 10 11 12