检查对象是否是 R 编程中的一个因素 - is.factor()函数
R 语言中的is.factor()
函数用于检查传递给函数的对象是否为因子。它返回一个布尔值作为输出。
Syntax: is.factor(Object)
Parameters:
Object: Object to be checked
示例 1:
# Creating a vector
x<-c("female", "male", "male", "female")
# Converting the vector x into a factor named gender
gender<-factor(x)
# Using is.factor() Function
is.factor(gender)
输出:
[1] TRUE
示例 2:
# Creating a vector
x<-c("female", "male", "male", "female")
# Converting the vector x into a factor named gender
gender<-factor(x)
# Using is.factor() Function
is.factor(x)
输出:
[1] FALSE