This function counts the number of unique subjects for each diagnosis in a dataframe.
If format_counts
is TRUE
, it returns a formatted string of counts.
count_unique_subjects_per_diagnosis(
df,
diagnosis_col,
subject_col,
format_counts = FALSE
)
A dataframe containing the data.
A string specifying the column name for diagnoses.
A string specifying the column name for subjects.
A boolean indicating whether to format counts as a single string in the format "x/y/z/q" where x, y, z, q represent the counts for each diagnosis. Defaults to FALSE.
A dataframe with two columns: Diagnosis and Unique_Subjects. If format_counts
is TRUE,
only the formatted counts are returned.
if (FALSE) { # \dontrun{
df <- data.frame(
diagnosis = c('A', 'A', 'B', 'A', 'B', 'C', 'C', 'C'),
subject_id = c(1, 2, 2, 3, 4, 5, 6, 6)
)
count_unique_subjects_per_diagnosis(df, 'diagnosis', 'subject_id')
count_unique_subjects_per_diagnosis(df, 'diagnosis', 'subject_id', format_counts = TRUE)
} # }