用法如下
ifelse.(conditions, true, false, na = NA)
简单展示如下
a<-c(1:10)
head(a)
## [1] 1 2 3 4 5 6
b<-ifelse(a>5,"大于5","小于5")
b
## [1] "小于5" "小于5" "小于5" "小于5" "小于5" "大于5" "大于5" "大于5" "大于5","大于5"
b<-as.factor(b)
levels(b)
#"大于5" "小于5"
str(b)
#Factor w/ 2 levels "大于5","小于5": 2 2 2 2 2 1 1 1 1 1
网友评论