Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

R Programming: Create a blank matrix

R Programming: Matrix Exercise-1 with Solution

Write a R program to create a blank matrix.

Sample Solution:

R Programming Code:

m = matrix(, nrow = 10, ncol = 5)
print("Empty matrix of 10 rows and 5 columns:")
print(m)

Sample Output:

[1] "Empty matrix of 10 rows and 5 columns:"
      [,1] [,2] [,3] [,4] [,5]
 [1,]   NA   NA   NA   NA   NA
 [2,]   NA   NA   NA   NA   NA
 [3,]   NA   NA   NA   NA   NA
 [4,]   NA   NA   NA   NA   NA
 [5,]   NA   NA   NA   NA   NA
 [6,]   NA   NA   NA   NA   NA
 [7,]   NA   NA   NA   NA   NA
 [8,]   NA   NA   NA   NA   NA
 [9,]   NA   NA   NA   NA   NA
[10,]   NA   NA   NA   NA   NA                     

R Programming Code Editor:



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

Previous: R programming Matrix Exercises Home.
Next: Write a R program to create a matrix taking a given vector of numbers as input. Display the matrix.

Test your Programming skills with w3resource's quiz.

What is the difficulty level of this exercise?