R Programming: Create a matrix taking a given vector of numbers as input
R Programming: Matrix Exercise-2 with Solution
Write a R program to create a matrix taking a given vector of numbers as input. Display the matrix.
Sample Solution:
R Programming Code:
M = matrix(c(1:16), nrow = 4, byrow = TRUE)
print("Original Matrix:")
print(M)
Sample Output:
[1] "Original Matrix:" [,1] [,2] [,3] [,4] [1,] 1 2 3 4 [2,] 5 6 7 8 [3,] 9 10 11 12 [4,] 13 14 15 16
R Programming Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a R program to create a blank matrix.
Next: Write a R program to create a matrix taking a given vector of numbers as input and define the column and row names. Display the matrix.
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