Skip to contents

Add categories for a numeric variable

Usage

num_cat(
  df,
  num_col,
  breaks,
  labels = NULL,
  int_undefined = c(-999, 999),
  char_undefined = "Unknown",
  new_colname = NULL,
  plus_last = FALSE,
  above_last = FALSE
)

Arguments

df

A dataframe.

num_col

The column name to recategorize.

breaks

A vector of cut points.

labels

A vector of labels.

int_undefined

A vector of values to replace by char_dontknow.

char_undefined

A character to replace int_dontknow values.

new_colname

The name of the new column.

plus_last

Logical, whether to add a "+" to the last category.

above_last

Logical, whether to add a category for values above the last break.

Value

A dataframe with a new column.