create_cat_var | R Documentation |
Using the grouping from either the 'decode_var' or 'code_var' and a reference variable ('ref_var') it will create a categorical variable and the numeric version of that categorical variable.
create_cat_var(data, metacore, ref_var, grp_var, num_grp_var = NULL)
data |
Dataset with reference variable in it |
metacore |
A metacore object to get the codelist from. If the variable has different codelists for different datasets the metacore object will need to be subsetted using 'select_dataset' from the metacore package. |
ref_var |
Name of variable to be used as the reference i.e AGE when creating AGEGR1 |
grp_var |
Name of the new grouped variable |
num_grp_var |
Name of the new numeric decode for the grouped variable. This is optional if no value given no variable will be created |
dataset with new column added
library(metacore)
library(haven)
library(dplyr)
load(metacore_example("pilot_ADaM.rda"))
spec <- metacore %>% select_dataset("ADSL")
dm <- read_xpt(metatools_example("dm.xpt")) %>%
select(USUBJID, AGE)
# Grouping Column Only
create_cat_var(dm, spec, AGE, AGEGR1)
# Grouping Column and Numeric Decode
create_cat_var(dm, spec, AGE, AGEGR1, AGEGR1N)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.