#' Get number of cases and controls
#' Last updated: 2020-06-21
#'
#' @param covariates A tibble
#' @param medications A tibble
#' @return A tibble \code{cohort_count}
#' @export
count_patients <- function(medications, covariates) {
##only keep covariates that are in `medications`
covariates <- covariates %>%
filter(person_id %in% medications$person_id)
##check if there are any patients that appear twice in table
num_rows <- nrow(covariates)
unique_patients <- n_distinct(covariates$person_id)
##get number of cases and controls
covariates1 <- covariates %>% group_by(groupc) %>% tally()
num_controls <- covariates1[1,2]
num_cases <- covariates1[2,2]
##create tibble with all results
cohort_count <- tibble(num_rows = num_rows,
unique_patients = unique_patients,
num_controls = num_controls,
num_cases = num_cases)
cohort_count
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.