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

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
主站蜘蛛池模板: 武穴市| 张家口市| 鹤庆县| 平乐县| 桑日县| 定结县| 泸州市| 仪陇县| 明星| 卢氏县| 白水县| 锡林浩特市| 大兴区| 泰和县| 文昌市| 江源县| 新源县| 钟山县| 图们市| 营口市| 郸城县| 玉山县| 维西| 疏附县| 阿荣旗| 浦城县| 濮阳县| 项城市| 凉城县| 兴山县| 赣榆县| 工布江达县| 平罗县| 日土县| 托里县| 秭归县| 西宁市| 石屏县| 垫江县| 通江县| 湘潭县|