group.to.vars {ROCpsych} | R Documentation |
Function to create new variables from the ordinal variable for further analysis
Description
This 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 repsrents participants at or below the selected category and 1 reprents 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.
Usage
group.to.vars(data, group, root.name=NULL)
Arguments
data |
A data frame or matrix that contains the ordinal variable. |
group |
The ordinal variable in the 'data' object. |
root.name |
Indicate whether a root name is used to name the new variables. If not specified (by default, root.name=NULL), the variable name will be used as the root. |
Value
A data frame with the original data and newly created variables.
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')