Learn R Programming

hutils (version 2.0.0)

selector: Fast selection of data.table columns

Description

Present since hutils 1.2.0.

Usage

selector(DT, ..., cols = NULL, preserve.key = TRUE, shallow = FALSE)

Value

DT with the selected columns.

Arguments

DT

A data.table.

...

Unquoted columns names.

cols

Character vector of column names.

preserve.key

(logical, default: TRUE) Reapply the key (if DT has one)?

shallow

(logical, default: FALSE) Should the result be a shallow copy of DT's columns or should the columns be assigned by reference? If TRUE, any modification to the result also modifies the selected columns in DT.

Examples

Run this code
RQ("nycflights13", no = {
 library(nycflights13)
 library(data.table)
 fs <- as.data.table(flights)
 fs1 <- selector(fs, year, month, day, arr_delay)
 fs1[, arr_delay := NA]
})

Run the code above in your browser using DataLab