在 R 编程中检查对象是否为整数类型 - is.integer()函数
R 语言中的is.integer()
函数用于检查作为参数传递给它的对象是否为整数类型。
Syntax: is.integer(x)
Parameters:
x: Object to be checked
示例 1:
# R program to check if
# object is an integer
# Creating a vector
x1 <- 4L
x2 <- c(1:6)
x3 <- c("a", "b", "c", "d")
x4 <- c(1, 2, "a", 3, "b")
# Calling is.integer() function
is.integer(x1)
is.integer(x2)
is.integer(x3)
is.integer(x4)
输出:
[1] TRUE
[1] TRUE
[1] FALSE
[1] FALSE
示例 2:
# R program to check if
# object is an integer
# Creating a matrix
x1 <- matrix(c(1:9), 3, 3)
# Calling is.integer() function
is.integer(x1)
输出:
[1] TRUE