| count_pattern | R Documentation |
Returns a named integer vector with elements that give the number of entries in the corresponding
column of df that match the string pattern pattern. No coercion is used
so only characters or factors are matched.
count_pattern(df, pattern, all = FALSE)
df |
A data frame. |
pattern |
Pattern to look for. Passed to |
all |
By default variables with no matches are omitted from the output. Set all=T to show all. |
Note that repeated occurrences of pattern in a single string are only counted once (see examples).
x <- data.frame(a = c("an", "banana", "candy"), b = c("on", "bon", "bonbon"), d = 1:3)
count_pattern(x, "an", all = TRUE)
count_pattern(x, "an")
count_pattern(x, "b")
count_pattern(x, "1") # not matched to integers
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.