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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to illustrate
# is.matrix function
  
# Specifying some different types of arrays
A <- 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() function
is.matrix(A)
is.matrix(B)
is.matrix(C)

chevron_right


Output:

[1] TRUE
[1] TRUE
[1] TRUE

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to illustrate
# is.matrix function
  
# Specifying Biochemical oxygen demand data
x <- BOD
  
# Calling is.matrix() function
is.matrix(x)
  
# Calling is.matrix() function
# over different types of data
is.matrix(4)
is.matrix("2")
is.matrix("a")

chevron_right


Output:

[1] FALSE
[1] FALSE
[1] FALSE
[1] FALSE
My Personal Notes arrow_drop_up

Recommended Posts:


Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.