rstpm2 (version 1.6.3)

incrVar: Utility that returns a function to increment a variable in a data-frame.

Description

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.

Usage

incrVar(var, increment = 1)

Value

A function with a single data argument that increments the variables in the data list/data-frame.

Arguments

var

String for the name(s) of the variable(s) to be incremented

increment

Value that the variable should be incremented.

Details

Useful for defining transformations for calculating rate ratios.

Examples

Run this code
##---- 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
    }
  }

Run the code above in your browser using DataLab