#' Double Count Two Times
#'
#' This function takes a date column and a categorical variable and returns a data frame with the number
#'
#' @family Special barplot
#' @seealso \code{\link{cat_barplot_double_count}} for creating the input data frame.
#'
#' @param df A data frame with at least two columns.
#' @param date_col A date column.
#' @param categorie_col A column with a categorie.
#'
#' @return A data frame with three columns:
#' \itemize{
#' \item The \code{categorie} column specified in the arguments.
#' \item \code{n:} is a count of the \code{categorie} column (Is useless without the next column).
#' \item \code{nn:} Count of number of days. This column denotes the count for the number of days
#' that \code{categorie} had a count of \code{n}.
#' }
#'
#' @export
#'
#' @examples
#' test <- nycflights13::flights %>%
#' dplyr::mutate(date = lubridate::as_date(paste(year, month, day, sep="-")))
#' head(dog_double_count(df = test, date_col = date, categorie_col = carrier))
#'
dog_double_count <- function(df, date_col, categorie_col) {
date_col <- rlang::enquo(date_col)
categorie_col <- rlang::enquo(categorie_col)
df %>%
filter(!is.na(!!date_col), !is.na(!!categorie_col)) %>%
count(!!date_col, !!categorie_col) %>%
tidyr::spread(!!categorie_col, n) %>%
replace(is.na(.), 0) %>%
tidyr::gather(-!!date_col, key= !! as_label(categorie_col), value="n") %>%
count(!!categorie_col, n)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.