Learn R Programming

qreport (version 1.0-1)

runDeriveExpr: runDeriveExpr

Description

Apply Derived Variable Specifications

Usage

runDeriveExpr(d, derv, pr = TRUE)

Value

nothing; used to print information and add variables to data table

Arguments

d

a data table

derv

a list of expressions to evaluate

pr

set pr=FALSE to suppress information messages

Author

Frank Harrell

Details

Function to apply derived variable specifications derv to a data table d. Actions on d are done in place, so call the function using runDeriveExpr(d, derv object) and not by running d <- runDeriveExpr(d, derv object). See this for an example.

Examples

Run this code
require(data.table)
d <- data.table(ht=c(68,  60), wt=c(280, 135), chol=c(120, 150))
derived <- list(
  list(bmi = expression(703 * wt / ht ^ 2),
       label='Body Mass Index',
       units='Kg/m^2'),
  list(bsa=expression(0.007184 * (0.4536 * wt) ^ 0.425 * (2.54 * ht) ^ 0.725),
       label='Body Surface Area',
       units='m^2', drop=.q(wt, ht) )   )
runDeriveExpr(d, derived)
print(d)
contents(d)

Run the code above in your browser using DataLab