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

View source: R/pm2-3.R

incrVarR Documentation

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)

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.

Value

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

Examples

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

rstpm2 documentation built on Oct. 29, 2024, 5:06 p.m.