R Programming: Convert a given matrix to a list
R Programming: List Exercise-13 with Solution
Write a R program to convert a given matrix to a list.
Sample Solution :
R Programming Code :
m = matrix(1:10,nrow=2, ncol=2)
print("Original matrix:")
print(m)
l = split(m, rep(1:ncol(m), each = nrow(m)))
print("list from the said matrix:")
print(l)
Sample Output:
[1] "Original matrix:" [,1] [,2] [1,] 1 3 [2,] 2 4 [1] "list from the said matrix:" $`1` [1] 1 2 $`2` [1] 3 4
R Programming Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a R program to convert a given dataframe to a list by rows.
Next: Write a R program to assign NULL to a given list element.
Test your Programming skills with w3resource's quiz.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework