For count_codes, it is assumed that all the columns apart from visit_name represent actual or possible ICD-9 codes. Duplicate visit_names are repeated as given and aggregated.

count_codes_wide(
  x,
  visit_name = get_visit_name(x),
  return_df = FALSE,
  aggr = FALSE
)

Arguments

x

data.frame with one row per patient, hospital visit, encounter, etc., and multiple columns containing any ICD codes attributed to that encounter or patient. i.e. data frame with ICD codes in wide format.

visit_name

The name of the column in the data frame which contains the patient or visit identifier. Typically this is the visit identifier, since patients come leave and enter hospital with different ICD-9 codes. It is a character vector of length one. If left empty, or NULL, then an attempt is made to guess which field has the ID for the patient encounter (not a patient ID, although this can of course be specified directly). The guesses proceed until a single match is made. Data frames may be wide with many matching fields, so to avoid false positives, anything but a single match is rejected. If there are no successful guesses, and visit_id was not specified, then the first column of the data frame is used.

return_df

single logical value, if TRUE, return 'tidy' data, i.e., the result is a data frame with the first column being the visit_id, and the second being the count. If visit_id was a factor or named differently in the input, this is preserved.

aggr

single logical, default is FALSE. If TRUE, the length (or rows) of the output will no longer match the input, but duplicate visit_names will be counted together.