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, ...)
dat |
|
---|---|
x |
|
copy | if |
sequential | if |
... | unused |
This is a more efficient implementation then coercing the data.table to a data.frame and use that implementation.
Other modify:
setmodify()
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#> age income #> 1: 130 300 #> 2: 11 0 #> 3: 25 3000