select: Selecting Variables

Description Usage Arguments Details Value See Also Examples

View source: R/select.R

Description

Select one or more expressions evaluated in the context of a data object.

Usage

1
2
3
4
5
select(`_data`, ...)
## S3 method for class 'dataset'
select(`_data`, ...)
## Default S3 method:
select(`_data`, ...)

Arguments

_data

a data object.

...

expressions to evaluate in the context of the data object.

Details

The select function evaluates a set of expressions in the context of a data object, returning the results as a data object with the results as variables.

The default implementation of the method coerces its _data argument to a dataset, then uses scope to evaluate the expressions in the context of the converted dataset. For the result, named arguments get these names as variable names; unnamed arguments get the deparsed expressions as names.

The expressions must evaluate to data objects with the same number of rows as _data.

If the _data object has keys, then these get propagated to the result.

Value

A data object with the evaluated expressions as variables.

See Also

transform.dataset, scope.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# evaluate expressions, take given names
select(iris,
       Sepal.Area = Sepal.Length * Sepal.Width,
       Petal.Area = Petal.Length * Petal.Width)


# propagate keys, take names from arguments
x <- as.dataset(mtcars)
keys(x) <- keyset(name = rownames(mtcars))
select(x, cyl, 2 * cyl, three = 3 * cyl)

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