Create Ordered Variable with Custom Breaks and Labels
create_ordered_variable_custom.Rd
This function creates an ordered categorical variable in a dataframe based on user-specified breaks and labels. It checks that the provided breaks and labels are correctly specified before creating the factor variable. This is useful for creating a factor with custom defined intervals.
Arguments
- df
A data frame containing the variable to be transformed.
- var_name
The name of the numeric variable within the data frame to be converted into an ordered factor. This variable should ideally be continuous.
- breaks
A numeric vector specifying the breakpoints between intervals. The breakpoints should cover the entire range of the variable and should be one more than the number of labels.
- labels
A character vector specifying the labels for the intervals defined by breaks. The length of labels should be one less than the length of breaks.