Skip to contents

Counts the number of words in each element of a character vector.

Usage

strCountW(x)

Arguments

x

a character vector

Value

An integer vector giving the number of words in each element of x.

Details

Words are detected using Unicode-aware word boundaries as implemented in stringi. This ensures robust handling of different languages, punctuation, and whitespace.

See also

stringi::stri_count_words()

string-overview for an overview of all string utilities in pharos.

Examples

strCountW("This is a sentence.")
#> [1] 4

strCountW(c("One word", "Two words here", NA))
#> [1]  2  3 NA