Skip to contents

add_age_cat() adds the age categories and add_age_18_cat() adds the age categories and a dummy variable for below and above 18.

Usage

add_age_cat(
  df,
  age_col,
  breaks = c(0, 18, 60, 120),
  labels = NULL,
  int_undefined = c(-999, 999),
  char_undefined = "undefined",
  new_colname = NULL
)

add_age_18_cat(
  df,
  age_col,
  int_undefined = c(-999, 999),
  char_undefined = "undefined",
  new_colname = NULL
)

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 of Pre.

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()).

Details

  • add_age_18_cat() adds two columns to the dataframe: one with the categories (minor, major) and one with a dummy variable for below and above 18.