Skip to contents

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.

Usage

create_cat_var(data, metacore, ref_var, grp_var, num_grp_var = NULL)

Arguments

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

Value

dataset with new column added

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, AGE)
# Grouping Column Only
create_cat_var(dm, spec, AGE, AGEGR1)
#> # A tibble: 306 × 3
#>    USUBJID       AGE AGEGR1
#>    <chr>       <dbl> <chr> 
#>  1 01-701-1015    63 <65   
#>  2 01-701-1023    64 <65   
#>  3 01-701-1028    71 65-80 
#>  4 01-701-1033    74 65-80 
#>  5 01-701-1034    77 65-80 
#>  6 01-701-1047    85 >80   
#>  7 01-701-1057    59 <65   
#>  8 01-701-1097    68 65-80 
#>  9 01-701-1111    81 >80   
#> 10 01-701-1115    84 >80   
#> # ℹ 296 more rows
# Grouping Column and Numeric Decode
create_cat_var(dm, spec, AGE, AGEGR1, AGEGR1N)
#> # A tibble: 306 × 4
#>    USUBJID       AGE AGEGR1 AGEGR1N
#>    <chr>       <dbl> <chr>    <dbl>
#>  1 01-701-1015    63 <65          1
#>  2 01-701-1023    64 <65          1
#>  3 01-701-1028    71 65-80        2
#>  4 01-701-1033    74 65-80        2
#>  5 01-701-1034    77 65-80        2
#>  6 01-701-1047    85 >80          3
#>  7 01-701-1057    59 <65          1
#>  8 01-701-1097    68 65-80        2
#>  9 01-701-1111    81 >80          3
#> 10 01-701-1115    84 >80          3
#> # ℹ 296 more rows