This function provides two main functionalities:
add_age_cat()
: Adds age categories to a dataframe based on specified breaks.add_age_18_cat()
: Adds age categories and a dummy variable for below and above 18 years old.
Arguments
- df
A dataframe.
- age_col
The column name to recategorize.
- breaks
A vector of cut points.
- labels
A vector of labels. If NULL, the labels will be the breaks.
- int_undefined
A vector of values undefined (such as -999, 999) to replace by char_undefined.
- char_undefined
A character to replace int_undefined values, often values corresponding to Don't know or Prefer not to answer.
- new_colname
The name of the new column. If NULL, it adds "_cat" to the age_col (or "_18_cat for
add_age_18_cat()
).