# R Programming: Convert a given matrix to a 1 dimensional array

## R Programming: Array Exercise-1 with Solution

Write a R program to convert a given matrix to a 1 dimensional array.

**Sample Solution** :

**R Programming Code :**

```
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

**R Programming Code Editor:**

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

**Previous:** R Programming Array Exercises Home.

**Next:** Write a R program to create an array of two 3x3 matrices each with 3 rows and 3 columns from two given two vectors.

Test your Programming skills with w3resource's quiz.

**What is the difficulty level of this exercise?**

**Weekly Trends and Language Statistics**- Weekly Trends and Language Statistics