subset.data.table

0th

Percentile

Subsetting data.tables

Returns subsets of a data.table.

Keywords
data
Usage
# S3 method for data.table
subset(x, subset, select, …)
Arguments
x

data.table to subset.

subset

logical expression indicating elements or rows to keep

select

expression indicating columns to select from data.table

further arguments to be passed to or from other methods

Details

The subset argument works on the rows and will be evaluated in the data.table so columns can be referred to (by name) as variables in the expression.

The data.table that is returned will maintain the original keys as long as they are not select-ed out.

Value

A data.table containing the subset of rows and columns that are selected.

See Also

subset

Aliases
  • subset
  • subset.data.table
Examples
# NOT RUN {
dt <- data.table(a=sample(c('a', 'b', 'c'), 20, replace=TRUE),
                 b=sample(c('a', 'b', 'c'), 20, replace=TRUE),
                 c=sample(20), key=c('a', 'b'))

sub <- subset(dt, a == 'a')
all.equal(key(sub), key(dt))
# }
Documentation reproduced from package data.table, version 1.10.4-1, License: GPL-3 | file LICENSE

Community examples

Looks like there are no examples yet.