Check if the Object is a Matrix in R Programming – is.matrix() Function
is.matrix() function in R Language is used to return TRUE if the specified data is in the form of matrix else return FALSE.
Syntax: is.matrix(x)
Parameters:
x: specified matrix
Example 1:
# R program to illustrate# is.matrix function # Specifying some different types of arraysA <- matrix(c(1:5))B <- matrix(c(1:12), nrow = 4, byrow = TRUE)C <- matrix(c(1:12), nrow = 4, byrow = FALSE) # Calling is.matrix() functionis.matrix(A)is.matrix(B)is.matrix(C) |
Output:
[1] TRUE [1] TRUE [1] TRUE
Example 2:
# R program to illustrate# is.matrix function # Specifying Biochemical oxygen demand datax <- BOD # Calling is.matrix() functionis.matrix(x) # Calling is.matrix() function# over different types of datais.matrix(4)is.matrix("2")is.matrix("a") |
Output:
[1] FALSE [1] FALSE [1] FALSE [1] FALSE


