subset {base} | R Documentation |
Return subsets of vectors or data frames which meet conditions.
subset(x, ...)
subset.default(x, subset, ...)
subset.data.frame(x, subset, select, ...)
x |
object to be subsetted |
... |
how to subset, depends on object |
subset |
logical expression |
select |
expression, indicating variables to select from a data frame |
For ordinary vectors, the result is simply
x[subset & !is.na(subset)]
.
For data frames, the subset
argument works similarly on the
rows. Note that subset
will be evaluated in the data frame.
The select
argument exists only for the method for data frames.
It works by
first replacing variable 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 examples ranges of
variables can be specified easily.
Selected rows and columns of the object x
.
Peter Dalgaard
[
,
transform
data(airquality)
subset(airquality, Temp > 80, select = c(Ozone, Temp))
subset(airquality, Day == 1, select = -Temp)
subset(airquality, select = Ozone:Wind)
attach(airquality)
subset(Ozone, Temp > 80)