Skip to contents

Categorize a numeric variable

Usage

addCategories(
  x,
  variable,
  categories,
  missingCategoryValue = "None",
  overlap = FALSE,
  name = NULL
)

Arguments

x

Table with individuals in the cdm.

variable

Target variable that we want to categorize.

categories

List of lists of named categories with lower and upper limit.

missingCategoryValue

Value to assign to those individuals not in any named category. If NULL or NA, missing will values will be given.

overlap

TRUE if the categories given overlap.

name

Name of the new table, if NULL a temporary table is returned.

Value

The x table with the categorical variable added.

Examples

# \donttest{
cdm <- mockPatientProfiles()

result <- cdm$cohort1 %>%
  addAge() %>%
  addCategories(
    variable = "age",
    categories = list("age_group" = list(
      "0 to 39" = c(0, 39), "40 to 79" = c(40, 79), "80 to 150" = c(80, 150)
    ))
  )
mockDisconnect(cdm = cdm)
# }