correctWithRules {deducorrect}R Documentation

Deterministic correction

Description

Apply simple replacement rules to a data.frame.

Usage

correctWithRules(rules, dat, strict = TRUE)

Arguments

rules

object of class correctionRules

dat

data.frame

strict

If TRUE, an error is produced when the rules use variables other than in the data.frame.

Value

list with altered data ($corrected) and a list of alterations ($corrections).

Details

This function applies the the 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.

See Also

correctionRules

Examples

## 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)

[Package deducorrect version 1.3.7 Index]