官术网_书友最值得收藏!

Factor levels

Levels are possible values that a variable can take. Suppose the original value of 1 is repeated; it will appear only once in the levels.

Factors can either be numeric or character variables, but levels of a factor can only be characters.

Let's run the level command:

levels(r)
## [1] "1" "4" "7" "8" "9"

As you can see, 1, 4, 7, 8, and 9 are the possible levels that the level r can have.

The exclude parameter allows you to exclude levels of a custom factor:

factor(r, exclude=4)
## [1] 1 <NA> 7 9 8 1
## Levels: 1 7 8 9

Finally, let's find out if our factor values are ordered or unordered:

a<- c(1,2,7,7,1,2,2,7,1,7)
a<- factor(a, levels=c(1,2,7), ordered=TRUE)
a
## [1] 1 2 7 7 1 2 2 7 1 7
## Levels: 1 < 2 < 7
主站蜘蛛池模板: 宝鸡市| 高平市| 辽阳县| 临泉县| 白城市| 航空| 苍山县| 遂川县| 文水县| 额敏县| 盐津县| 华安县| 化隆| 莒南县| 泸定县| 雅江县| 繁峙县| 南陵县| 灵川县| 沈阳市| 惠来县| 伊吾县| 出国| 吉林省| 图们市| 正镶白旗| 哈尔滨市| 桃江县| 新邵县| 鄢陵县| 广德县| 五大连池市| 长汀县| 昌图县| 手机| 司法| 花垣县| 广饶县| 娱乐| 怀集县| 黔西|