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

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
主站蜘蛛池模板: 迁安市| 康平县| 庆安县| 安国市| 武宁县| 韶山市| 高陵县| 都匀市| 英吉沙县| 英吉沙县| 乌恰县| 崇信县| 鹤庆县| 灵武市| 庆阳市| 长顺县| 祁门县| 武安市| 黎城县| 石楼县| 元朗区| 清镇市| 永清县| 察哈| 广安市| 柳河县| 永昌县| 濉溪县| 布尔津县| 攀枝花市| 泗洪县| 甘泉县| 伊春市| 漯河市| 蒲城县| 张家川| 苏尼特左旗| 永春县| 靖西县| 怀来县| 溧阳市|