select_which: Select columns satisfying a condition

View source: R/select_which.R

select_whichR Documentation

Select columns satisfying a condition

Description

Select columns satisfying a condition

Usage

select_which(DT, Which, .and.dots = NULL, checkDT = TRUE, .and.grep = NULL)

Arguments

DT

A data.table.

Which

A function that takes a vector and returns TRUE or FALSE. TRUE columns are selected.

.and.dots

Optional extra columns to include. May be a character vector of names(DT) or numeric (positions) or logical. If provided, the columns so added (if they do not satisfy Which) will be after all the columns Which do so satisfy.

checkDT

If TRUE (the default), an informative error message is provided if DT is not a data.table.

.and.grep

A character vector of regular expressions to match to the names of DT. The corresponding columns will be included in the result.

Value

DT with the selected variables.

Examples

library(data.table)
DT <- data.table(x = 1:5,
                 y = letters[1:5],
                 AB = c(NA, TRUE, FALSE))
select_which(DT, anyNA, .and.dots = "y")

HughParsonage/hutils documentation built on Feb. 12, 2023, 8:26 a.m.