subset: Subsetting Datasets

Description Usage Arguments Details Value See Also Examples

Description

Extract a subset of the rows of a dataset using a logical condition.

Usage

1
2
## S3 method for class 'dataset'
subset(x, subset, ...)

Arguments

x

a dataset object.

subset

a logical expression giving the subset condition.

...

ignored.

Details

The subset.dataset first converts its first argument do a dataset and then extracts the rows corresponding to the TRUE elements in the subset argument. When evaluating the subset condition, the method quotes the argument and then evaluates it using scope, with the dataset-converted x as the first argument.

The method is similar to subset.data.frame, but method, but it lacks additional arguments beyond subset, and it uses a different evaluation mechanism for the subset argument.

Value

A dataset containing the rows in x corresponding to the TRUE elements of the evaluated subset condition.

See Also

scope, subset.data.frame.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
x <- as.dataset(mtcars)
subset(x, cyl == 4)

# equivalent:
subset.dataset(mtcars, cyl == 4)

# scoped evaluation:
gear <- 1:nrow(mtcars)
subset(x, gear == 5)    # look for 'gear' in 'x', then the environment
subset(x, I(gear) == 5) # look for 'gear' in the environment

patperry/r-frame documentation built on May 6, 2019, 8:34 p.m.