因子用来存储类别变量(categorical variables)和有序变量,用来分类或者计数。可以利用factor() 或者ordered() 两个函数将普通变量转换成有序因子
例如:
> A=c("a","c","e","b","d")
factor
> B=factor(A,levels=c("a","b","c","d","e"),ordered = T)
> B
[1] a c e b d
Levels: a < b < c < d < e
ordered
> C=ordered(A,labels=c("a","b","c","d","e"))
> C
[1] a c e b d
Levels: a < b < c < d < e
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!