setj: Conditional column manipulation by reference

setjR Documentation

Conditional column manipulation by reference

Description

These functions manipulate existing columns of your data.table by reference based on a selection of columns, a predicate function or a regex pattern that the column name must match.

Usage

setj_at(DT, cols, .f, ...)

setj_if(DT, .p, .f, ...)

setj_grep(DT, pattern, .f, ...)

Arguments

DT

(data.table::data.table())
A data.table.

cols

(numeric() or character())
A vector of integer column indices or character column names.

.f

(⁠function()⁠)
A function that will be applied by reference to the matching columns

...

Additional function arguments you want to supply to .f.

.p

(⁠function()⁠)
A predicate function that will be applied to all columns and returns a logical vector.

pattern

(character(1))
A regular expression pattern as used by grep().

Details

setj_at() takes an integer (!) vector of column indices or a character vector of column names as input for cols and applies .f on the corresponding columns. If you supply indices or column names which don't exist in your data.table you will get an informative message.

setj_if() takes a predicate function as input for .p. The function .f will then be applied to those columns for which .p returns TRUE. If the predicate function returns FALSE for all columns you will get an informative message.

setj_grep() manipulates columns based on regular expression pattern matches. For that you need to pass a single regex pattern to the pattern argument. If the pattern doesn't match any of your data.table columns you will get an informative message.

Value

(data.table::data.table())
The functions invisibly return the modified data.table.


DavidJesse21/data.table.utils documentation built on March 26, 2023, 7:19 a.m.