In R, you can create a zero matrix using the matrix()
function and specifying the number of rows and columns. By default, this function initializes all elements to zero.
In this example,
matrix()
function to create a 3x3 zero matrix. The arguments nrow
and ncol
specify the number of rows and columns in the matrix, respectively.zero_mat
.zero_mat
to the console to verify the creation of the zero matrix.zero_mat <- matrix(0, nrow = 3, ncol = 3)
print(zero_mat)
[,1] [,2] [,3] [1,] 0 0 0 [2,] 0 0 0 [3,] 0 0 0
In this example,
matrix()
function to create a 4x2 zero matrix. The arguments nrow
and ncol
specify the number of rows and columns in the matrix, respectively.zero_mat
.zero_mat
to the console to verify the creation of the zero matrix.zero_mat <- matrix(0, nrow = 4, ncol = 2)
print(zero_mat)
[,1] [,2] [1,] 0 0 [2,] 0 0 [3,] 0 0 [4,] 0 0
In this tutorial, we learned How to Create Zero Matrix in R language with well detailed examples.