Description Usage Arguments Note
These function adds variance and percent variance columns to a data.table for each of the vars specified.
add_var_cols2() performs the same operations as add_var_cols2() but it also rehsapes the data.table
using data.table's dcast() based on the variable names provided in row_vars.
1 2 3 4 5 6 | add_var_cols(D, vars = c("cost_pmpm", "claims_per_1000",
"cost_per_claim"), reorder = T, format.pct = T)
add_var_cols2(D, vars = c("cost_pmpm", "claims_per_1000",
"cost_per_claim"), reorder = T, format.pct = T,
row_vars = c("product", "region", "mmcor_desc"))
|
D |
A data.table |
vars |
A character vector of column names to use to calculate new variance columns |
reorder |
Logical, if |
format.pct |
Logical, if |
row_vars |
A character vector of column names that will serve as the unique rows of the final data.table - usually product, region, and mmcor_desc |
add_var_cols() does not need to be reassigned to an R object, however add_var_cols2() does need to be reassigned.
Variables cannot be included in both var and row_vars and variables appearing in neither are automatically dropped.
If using add_var_cols2() a column col must exist containing two values 'prior' and 'current'.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.