
data.frame
.
correctWithRules(rules, dat, strict = TRUE)
correctionRules
data.frame
TRUE
, an error is produced when the rules use variables other than in the data.frame
.$corrected
) and a list of alterations ($corrections
).
rules
one by one to dat
and logs
their actions. Rules are excuted in order of occurrence in the correctionRules
so order may matter for the final result. Rules are applied to one record at the time, so
the use of statistical funtions such as mean
is useless, and forbidden by default.
See correctionRules
for details on the type of rules that are possible.correctionRules
## Some example data
dat <- data.frame(
x = c(NA, 2, 0,-10),
y = c(1, NA,NA, 6)
)
## a few rules
u <- correctionRules(expression(
if ( is.na(x) ) x <- 0,
if ( x == 0 && is.na(y) ) y <- 0,
if ( is.na(y) ) y <- 1,
if ( x < 0 ) y <- 0
))
correctWithRules(u,dat)
Run the code above in your browser using DataLab