convert_var_to_fct | R Documentation |
This functions takes a dataset, a metacore object and a variable name. Then looks at the metacore object for the control terms for the given variable and uses that to convert the variable to a factor with those levels. If the control terminology is a code list, the code column will be used. The function fails if the control terminology is an external library
convert_var_to_fct(data, metacore, var)
data |
A dataset containing the variable to be modified |
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 |
var |
Name of variable to change |
Dataset with variable changed to a factor
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, SEX, ARM)
# Variable with codelist control terms
convert_var_to_fct(dm, spec, SEX)
# Variable with permitted value control terms
convert_var_to_fct(dm, spec, ARM)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.