as.factor()发挥作用R语言用于将传递的对象(通常为Vector)转换为因子。
语法:as.factor(object)参数:Object:要转换的向量
范例1:
# Creating a vector
x< - c( "female" , "male" , "male" , "female" )
# Using as.factor() Function
# to convert vector into factor
as.factor(x)
输出如下:
[1] female male male female
Levels: female male
范例2:
# Creating a vector
x< - c( "North" , "North" , "East" , "West" )
# Using as.factor() Function
# to convert vector into factor
as.factor(x)
输出如下:
[1] North North East West
Levels: East North West