subset(base)
subset()所属R语言包:base
Subsetting Vectors, Matrices and Data Frames
子集向量,矩阵和数据框
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Return subsets of vectors, matrices or data frames which meet conditions.
返回向量,矩阵或符合条件的数据框的子集。
用法----------Usage----------
subset(x, ...)
## Default S3 method:[默认方法]
subset(x, subset, ...)
## S3 method for class 'matrix'
subset(x, subset, select, drop = FALSE, ...)
## S3 method for class 'data.frame'
subset(x, subset, select, drop = FALSE, ...)
参数----------Arguments----------
参数:x
object to be subsetted.
反对将子集。
参数:subset
logical expression indicating elements or rows to keep: missing values are taken as false.
逻辑表达式表示元素或行保留:遗漏值都为假。
参数:select
expression, indicating columns to select from a data frame.
表达,表示列选择一个数据框。
参数:drop
passed on to [ indexing operator.
传递[索引运营商。
参数:...
further arguments to be passed to or from other methods.
进一步的参数被传递到或从其他方法。
Details
详情----------Details----------
This is a generic function, with methods supplied for matrices, data frames and vectors (including lists). Packages and users can add further methods.
这是一个通用的功能,矩阵,数据框和向量(包括名单)提供的方法。软件包,用户可以添加更多的方法。
For ordinary vectors, the result is simply x[subset & !is.na(subset)].
对于普通的向量,其结果是简单x[subset & !is.na(subset)]。
For data frames, the subset argument works on the rows. Note that subset will be evaluated in the data frame, so columns can be referred to (by name) as variables in the expression (see the examples).
对于数据框,subset参数工作就行。注意subset将在数据框评估,所以列可以被称为表达式中的变量(名称)(见例子)。
The select argument exists only for the methods for data frames and matrices. It works by first replacing column names in the selection expression with the corresponding column numbers in the data frame and then using the resulting integer vector to index the columns. This allows the use of the standard indexing conventions so that for example ranges of columns can be specified easily, or single columns can be dropped (see the examples).
select参数只存在数据框和矩阵的方法。它通过在数据框中相应的列数,然后使用所产生的整数索引的列向量的选择表达取代列名第一。这允许使用标准索引约定,因此,例如列范围,可以指定轻松,或单一的列可以被丢弃(见例子)。
The drop argument is passed on to the indexing method for matrices and data frames: note that the default for matrices is different from that for indexing.
drop参数被传递到方法:请注意,默认为矩阵是不同的索引矩阵和数据框的索引。
Factors may have empty levels after subsetting; unused levels are not automatically removed. See droplevels for a way to drop all unused levels from a data frame.
因素可能有子集空后的水平,不会自动删除未使用的水平。看到droplevels的方式放弃所有未使用的水平,从一个数据框。
值----------Value----------
An object similar to x contain just the selected elements (for a vector), rows and columns (for a matrix or data frame), and so on.
对象类似x包含选定的元素(向量),行和列(矩阵或数据框),等等。“
警告----------Warning----------
This is a convenience function intended for use interactively. For programming it is better to use the standard subsetting functions like [, and in particular the non-standard evaluation of argument subset can have unanticipated consequences.
这是一个方便的功能,使用交互。编程最好是使用标准的子集功能,如[,特别是非标准参数subset评价可以有意想不到的后果。
作者(S)----------Author(s)----------
Peter Dalgaard and Brian Ripley
参见----------See Also----------
[, transform droplevels
[,transformdroplevels
举例----------Examples----------
subset(airquality, Temp > 80, select = c(Ozone, Temp))
subset(airquality, Day == 1, select = -Temp)
subset(airquality, select = Ozone:Wind)
with(airquality, subset(Ozone, Temp > 80))
## sometimes requiring a logical 'subset' argument is a nuisance[#有时需要一个逻辑的“子集”的说法是滋扰]
nm <- rownames(state.x77)
start_with_M <- nm %in% grep("^M", nm, value=TRUE)
subset(state.x77, start_with_M, Illiteracy:Murder)
# but in recent versions of R this can simply be[但在最近版本的R这可以简单地]
subset(state.x77, grepl("^M", nm), Illiteracy:Murder)
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|