Modify records in a data.table using modification rules specified in a modifier object.

# S4 method for data.table,modifier
modify(dat, x, copy = NULL, sequential = TRUE, ...)

Arguments

dat

data.table() object

x

dcmodify::modifier object.

copy

if TRUE modify copy of table.

sequential

if TRUE (default), steps will be executed in sequence, so order matters.

...

unused

Details

This is a more efficient implementation then coercing the data.table to a data.frame and use that implementation.

See also

Other modify: setmodify()

Examples

library(data.table) m <- modifier( if (age > 130) age = 130 , income[age < 12] <- 0 ) dat <- fread(text = "age, income 140, 300 11, 2000 25, 3000" ) # modify a copy of the data dat_m <- modify(dat, m, copy = TRUE) print(dat_m)
#> age income #> 1: 130 300 #> 2: 11 0 #> 3: 25 3000
# the data it self setmodify(dat, m) print(dat)
#> age income #> 1: 130 300 #> 2: 11 0 #> 3: 25 3000