count: count string occurrences

View source: R/count.R

countR Documentation

count string occurrences

Description

count how often a certain string occurs, summing over a vector

Usage

count(pattern, x, ...)

Arguments

x

charstring (vector)

...

Further arguments passed to gregexpr

a

character string (can have regex)

Value

single integer

Author(s)

Berry Boessenkool, berry-b@gmx.de, Jan 2025

Examples

vec210 <- c("with abc + abc + ab", "also abcde", "no alphabet")
vec021 <- c("no alphabet", "this has abcabc + ab", "also abcde")
vec000 <- c("this has no", "alphabet", "at all")
vec4 <-     "this has abc and abcabcabc"
stopifnot(count("abc", vec210) == 3)
stopifnot(count("abc", vec021) == 3)
stopifnot(count("abc", vec000) == 0)
stopifnot(count("abc", vec4  ) == 4)


brry/berryFunctions documentation built on Feb. 15, 2025, 12:10 a.m.