View source: R/derive_vars_cat.R
| derive_vars_cat | R Documentation |
AVALCATy and AVALCAyNDerive Categorization Variables Like AVALCATy and AVALCAyN
derive_vars_cat(dataset, definition, by_vars = NULL)
dataset |
Input dataset The variables specified by the |
definition |
List of expressions created by Must contain:
e.g. if exprs(~condition, ~AVALCAT1, ~AVALCA1N,
AVAL >= 140, ">=140 cm", 1,
AVAL < 140, "<140 cm", 2)
e.g. if exprs(~VSTEST, ~condition, ~AVALCAT1, ~AVALCA1N,
"Height", AVAL >= 140, ">=140 cm", 1,
"Height", AVAL < 140, "<140 cm", 2)
|
by_vars |
list of expressions with one element. |
If conditions are overlapping, the row order of definitions must be carefully considered.
The first match will determine the category.
i.e. if
AVAL = 155
and the definition is:
definition <- exprs( ~VSTEST, ~condition, ~AVALCAT1, ~AVALCA1N, "Height", AVAL > 170, ">170 cm", 1, "Height", AVAL <= 170, "<=170 cm", 2, "Height", AVAL <= 160, "<=160 cm", 3 )
then AVALCAT1 will be "<=170 cm", as this is the first match for AVAL.
If you specify:
definition <- exprs( ~VSTEST, ~condition, ~AVALCAT1, ~AVALCA1N, "Height", AVAL <= 160, "<=160 cm", 3, "Height", AVAL <= 170, "<=170 cm", 2, "Height", AVAL > 170, ">170 cm", 1 )
Then AVAL <= 160 will lead to AVALCAT1 == "<=160 cm",
AVAL in-between 160 and 170 will lead to AVALCAT1 == "<=170 cm",
and AVAL <= 170 will lead to AVALCAT1 == ">170 cm".
However, we suggest to be more explicit when defining the condition, to avoid overlap.
In this case, the middle condition should be:
AVAL <= 170 & AVAL > 160
The input dataset with the new variables defined in definition added
General Derivation Functions for all ADaMs that returns variable appended to dataset:
derive_var_extreme_flag(),
derive_var_joined_exist_flag(),
derive_var_merged_ef_msrc(),
derive_var_merged_exist_flag(),
derive_var_obs_number(),
derive_var_relative_flag(),
derive_vars_computed(),
derive_vars_joined(),
derive_vars_joined_summary(),
derive_vars_merged(),
derive_vars_merged_lookup(),
derive_vars_merged_summary(),
derive_vars_transposed()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.