levels(base)
levels()所属R语言包:base
Levels Attributes
各级属性
译者:生物统计家园网 机器人LoveR
描述----------Description----------
levels provides access to the levels attribute of a variable. The first form returns the value of the levels of its argument and the second sets the attribute.
levels提供变量的访问级别的属性。第一种形式返回其参数的水平值和第二的属性设置。
用法----------Usage----------
levels(x)
levels(x) <- value
参数----------Arguments----------
参数:x
an object, for example a factor.
一个对象,例如一个因素。
参数:value
A valid value for levels(x). For the default method, NULL or a character vector. For the factor method, a vector of character strings with length at least the number of levels of x, or a named list specifying how to rename the levels.
levels(x)的一个有效的值。对于默认的方法,NULL或特征向量。 factor方法,字符串长度的向量至少x,或命名列表各级数指定如何命名的水平。
Details
详情----------Details----------
Both the extractor and replacement forms are generic and new methods can be written for them. The most important method for the replacement function is that for factors.
同时提取和替代形式是通用的,新方法,可以为他们写的。替换功能最重要的方法是factor的。
For the factor replacement method, a NA in value causes that level to be removed from the levels and the elements formerly with that level to be replaced by NA.
因子替代方法,NAvalue导致该级别水平和元素从以前与该级别由NA取代。
Note that for a factor, replacing the levels via levels(x) <- value is not the same as (and is preferred to) attr(x, "levels") <- value.
注意的一个因素,取代通过levels(x) <- value水平是不一样的(首选)attr(x, "levels") <- value。
The replacement function is primitive.
是原始的替换功能。
参考文献----------References----------
The New S Language. Wadsworth & Brooks/Cole.
参见----------See Also----------
nlevels, relevel, reorder.
nlevels,relevel,reorder。
举例----------Examples----------
## assign individual levels[#指定个人的水平]
x <- gl(2, 4, 8)
levels(x)[1] <- "low"
levels(x)[2] <- "high"
x
## or as a group[#或为一组]
y <- gl(2, 4, 8)
levels(y) <- c("low", "high")
y
## combine some levels[#一些水平结合起来。]
z <- gl(3, 2, 12)
levels(z) <- c("A", "B", "A")
z
## same, using a named list[#一样,使用一个名为名单]
z <- gl(3, 2, 12)
levels(z) <- list(A=c(1,3), B=2)
z
## we can add levels this way:[#我们可以添加水平,这种方式:]
f <- factor(c("a","b"))
levels(f) <- c("c", "a", "b")
f
f <- factor(c("a","b"))
levels(f) <- list(C="C", A="a", B="b")
f
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|