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

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
主站蜘蛛池模板: 土默特右旗| 买车| 大竹县| 吴堡县| 华安县| 盐池县| 蒙城县| 乐昌市| 晋城| 马山县| 文安县| 大姚县| 登封市| 淮阳县| 宁河县| 吉林市| 新龙县| 洛宁县| 衡南县| 桂东县| 武陟县| 余姚市| 贵港市| 甘洛县| 邵阳市| 铁力市| 晋城| 论坛| 伊宁县| 武胜县| 巴彦县| 晋州市| 昌图县| 兴海县| 湖南省| 南溪县| 明溪县| 阳泉市| 纳雍县| 太原市| 上思县|