Title: | Modification Rules on 'data.table' |
---|---|
Description: | Apply 'dcmodify' rules on a 'data.table', code generated is optimized for changing a data.table in place / by reference. |
Authors: | Edwin de Jonge [aut, cre] |
Maintainer: | Edwin de Jonge <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0.9000 |
Built: | 2024-11-22 02:50:04 UTC |
Source: | https://github.com/data-cleaning/dcmodifydt |
Dump data.table modification script
dump_dt(x, name = "dat", file = stdout())
dump_dt(x, name = "dat", file = stdout())
x |
|
name |
|
file |
where should the generated file be written? |
library(dcmodify) m <- modifier( if (age > 130) age = 130 , income[age < 12] <- 0 ) dump_dt(m, "my_data")
library(dcmodify) m <- modifier( if (age > 130) age = 130 , income[age < 12] <- 0 ) dump_dt(m, "my_data")
Modify records in a data.table using modification rules specified in a modifier object.
## S4 method for signature 'data.table,modifier' modify(dat, x, copy = NULL, sequential = TRUE, ...)
## S4 method for signature '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) # the data it self setmodify(dat, m) print(dat)
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) # the data it self setmodify(dat, m) print(dat)
modifies data.table in place, alias for modify
with copy=TRUE
and
sequential=TRUE
. It follows the naming convention in data.table
to
prefix methods that change objects (byreference) with set
.
setmodify(dat, x, ...)
setmodify(dat, x, ...)
dat |
|
x |
|
... |
not used |
Other modify:
modify,data.table,modifier-method
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) # the data it self setmodify(dat, m) print(dat)
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) # the data it self setmodify(dat, m) print(dat)