R/count.R

Defines functions count

Documented in count

#' Count Characters in a Chars Object
#'
#' @param x A vector of characters.
#' @param value character (length 1) to count
#' @param ignore.case should the letter case be ignored?
#'
#' @return integer, count of instances of `value` in `x`
#' @export
#'
#' @examples
#' count(chars("strawberry"), 3)
count <- function(x, value, ignore.case = FALSE) {
  if (ignore.case) {
    x <- tolower(x)
    value <- tolower(value)
  }
  sum(x == value, na.rm = TRUE)
}

Try the charcuterie package in your browser

Any scripts or data that you put into this service are public.

charcuterie documentation built on April 3, 2025, 8:53 p.m.