R因子
Posted 智能先行者
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了R因子相关的知识,希望对你有一定的参考价值。
factor(x = character(), levels, labels = levels,
exclude = NA, ordered = is.ordered(x), nmax = NA)
levels因子水平,如果不指定,就是x中所有不重复的值
labels水平标识名称
exclude排除哪些水平
ordered—TRUE表示有序因子,FALSE表示无序因子
nmax水平个数上限
> f<-c("Spark","RDD","Scala","MLlib","GraghX", "Spark","Scala","GraghX","Spark","Scala")
> f1<-factor(f)
> class(f1)
[1] "factor"
> str(f1)
Factor w/ 5 levels "GraghX","MLlib",..: 5 3 4 2 1 5 4 1 5 4
> length(f1) 数据长度,而不是个数
[1] 10
> f2<-factor(f,levels=c("Spark","RDD","Scala"))
> f2
[1] Spark RDD Scala <NA> <NA> Spark
[7] Scala <NA> Spark Scala
Levels: Spark RDD Scala
> f3<-factor(f,levels=c("Spark","RDD","Scala","MLlib","GraghX","Hadoop","Hive"))
> f3
[1] Spark RDD Scala MLlib GraghX
[6] Spark Scala GraghX Spark Scala
7 Levels: Spark RDD Scala ... Hive
> fa<-c(1,2)
> fa1<-factor(fa,labels = c("男","女"))
> str(fa1)
Factor w/ 2 levels "男","女": 1 2
以上是关于R因子的主要内容,如果未能解决你的问题,请参考以下文章
在 R 的 randomForest 包中,因子是不是必须明确标记为因子?