Function to create new variables from the ordinal variable for further analysis
group.to.vars.RdThis function collapses group memberships or categories of the ordinal variable into binary variables (or indicators) for each category and appends the new variables to the end of the original data. For each new variable, 0 represents participants at or below the selected category and 1 represents participants above the selected category. For example, age.40 = 0 means participants with age at or below 40, whereas age.40 = 1 indicates participants with age beyond 40.
Examples
#read the example data
data(ROC.data.ex)
#create new binary variables for the ordinal variable
data.new.age<-group.to.vars(ROC.data.ex,
ROC.data.ex$age,
root.name='age')
#> [1] "A total number of 43 unique categories are identified"
#> [1] 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
#> [26] 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 83 84 87