R/prop_count.R

Defines functions prop_count

Documented in prop_count

#' adds proportion values to count() function
#'
#' adds proportion values to count() function
#' @param data is the data
#' @param ... the variables for which to count unique levels
#' @digits the number of digits to round to
#' @keywords proportional count
#' @export
#' @examples
#' prop_count(mtcars, cyl)

prop_count <- function(data, ..., digits = 2){
  data %>%
    dplyr::count(...) %>%
    dplyr::mutate(prop = round(n / sum(n), digits))
}
Kidapt/keda documentation built on Oct. 15, 2019, 9:01 p.m.