charCount | R Documentation |
Counts the number of times a specified pattern appears in a given text string or vector of strings. If the pattern is a single character or a sequence of characters, the function returns the number of occurrences of the pattern in "stosearch".
charCount(pattern, stosearch, ignore.case = FALSE)
pattern |
Character. The pattern to search for within the text string(s). |
stosearch |
Character. The text string(s) in which to search for the pattern. |
ignore.case |
Logical. If TRUE, the search is case-insensitive. Default is FALSE. |
When the pattern is a regular expression, the function returns the number of times the expression matches in "stosearch". For specific regex patterns like ".", you should escape it: e.g., charCount("\.txt", c("test.txt", "sample.txt")).
Integer. The total count of occurrences of the pattern in the text string(s).
nchar
charCount("a", "banana") # Returns 3 (three 'a's in "banana")
charCount("a", c("banana", "apple")) # Returns 4
charCount("\\d", "13ab2c") # Returns 3 (three digits in "13ab2c")
charCount("\\.txt", c("test.txt", "sample.txt"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.