Learn R Programming

udpipe (version 0.8.11)

txt_count: Count the number of times a pattern is occurring in text

Description

Count the number of times a pattern is occurring in text. Pattern counting is performed by executing a regular expression using gregexpr and checking how many times the regular expression occurs.

Usage

txt_count(x, pattern, ...)

Value

an integer vector of the same length as x indicating how many times the pattern is occurring in x

Arguments

x

a character vector with text

pattern

a text pattern which might be contained in x

...

other arguments, passed on to gregexpr

Examples

Run this code
x <- c("abracadabra", "ababcdab", NA)
txt_count(x, pattern = "ab")
txt_count(x, pattern = "AB", ignore.case = TRUE)
txt_count(x, pattern = "AB", ignore.case = FALSE)

Run the code above in your browser using DataLab