incrVar | R Documentation |
A functional approach to defining an increment in one or more variables in a data-frame. Given a variable name and an increment value, return a function that takes any data-frame to return a data-frame with incremented values.
incrVar(var, increment = 1)
var |
String for the name(s) of the variable(s) to be incremented |
increment |
Value that the variable should be incremented. |
Useful for defining transformations for calculating rate ratios.
A function with a single data
argument that increments the variables
in the data
list/data-frame.
##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (var, increment = 1)
{
n <- length(var)
if (n > 1 && length(increment)==1)
increment <- rep(increment, n)
function(data) {
for (i in 1:n) {
data[[var[i]]] <- data[[var[i]]] + increment[i]
}
data
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.