Select columns satisfying a condition

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

library(data.table) DT <- data.table(x = 1:5, y = letters[1:5], AB = c(NA, TRUE, FALSE))
#> Warning: Item 3 is of size 3 but maximum size is 5 (recycled leaving remainder of 2 items)
select_which(DT, anyNA, .and.dots = "y")
#> AB y #> 1: NA a #> 2: TRUE b #> 3: FALSE c #> 4: NA d #> 5: TRUE e