Description Usage Arguments Value Details See Also Examples
Apply simple replacement rules to a data.frame
.
1 | correctWithRules(rules, dat, strict = TRUE)
|
rules |
object of class |
dat |
|
strict |
If |
list with altered data ($corrected
) and a list of alterations ($corrections
).
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | ## 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)
|
Loading required package: editrules
Loading required package: igraph
Attaching package: 'igraph'
The following objects are masked from 'package:stats':
decompose, spectrum
The following object is masked from 'package:base':
union
Attaching package: 'editrules'
The following objects are masked from 'package:igraph':
blocks, normalize
$corrected
x y
1 0 1
2 2 1
3 0 0
4 -10 0
$corrections
row variable old new how
1 1 x NA 0 if (is.na(x)) x <- 0
2 2 y NA 1 if (is.na(y)) y <- 1
3 3 y NA 0 if (x == 0 && is.na(y)) y <- 0
4 4 y 6 0 if (x < 0) y <- 0
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.