检查对象是否是 R 编程中的矩阵 - is.matrix()函数
R语言中的is.matrix()
函数用于如果指定的数据是矩阵形式返回TRUE,否则返回FALSE。
Syntax: is.matrix(x)
Parameters:
x: specified matrix
示例 1:
# 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)
输出:
[1] TRUE
[1] TRUE
[1] TRUE
示例 2:
# 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")
输出:
[1] FALSE
[1] FALSE
[1] FALSE
[1] FALSE