convert_var_to_fct {metatools} | R Documentation |
Convert Variable to Factor with Levels Set by Control Terms
Description
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
Usage
convert_var_to_fct(data, metacore, var)
Arguments
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 'select_dataset' from the metacore package |
var |
Name of variable to change |
Value
Dataset with variable changed to a factor
Examples
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)
[Package metatools version 0.1.6 Index]