hutils (version 1.5.0)

select_which: Select columns satisfying a condition

Description

Select columns satisfying a condition

Usage

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

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.

Value

DT with the selected variables.

Examples

Run this code
# NOT RUN {
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")
# }

Run the code above in your browser using DataLab