首页 > 其他 > 详细

R因子

时间:2016-11-22 01:53:32      阅读:154      评论:0      收藏:0      [点我收藏+]

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因子

原文:http://www.cnblogs.com/wwxbi/p/6087378.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!