View source: R/count_matches.R
count_matches | R Documentation |
Counts the number of entries of each column in a data frame that exactly match the supplied values. No coercion is used so the type must also match (unless the column is a factor in which case character values will be matched to levels).
count_matches2()
is a deprecated function that has been replaced by the detail
argument.
count_matches(
df,
values = string_missing(),
all = FALSE,
prop = FALSE,
detail = FALSE
)
count_matches2(df, values = string_missing(), all = FALSE, prop = FALSE)
df |
A data frame. |
values |
Vector of values to match. |
all |
By default, columns or values with no matches are omitted from the output.
Set |
prop |
Default is to return counts of matches. Set |
detail |
Logical. If |
A named integer vector or tibble depending on the detail
argument.
x <- data.frame(a = c("an", "banana", "candy"), b = c("on", "bon", "bonbon"), c = 1:3)
count_matches(x, "an", all = TRUE)
count_matches(x, "an")
count_matches(x, 1L)
count_matches(x, 1) # type must match
count_matches(x, "1") # type must match
df <- data.frame(x1 = c("a", ".", ".", "a"),
x2 = c("-", "-", "b", "b"),
x3 = rep("z", 4),
x4 = c("n/a", "f", "f", ""))
strs <- c(".", "-", "n/a", "na", "")
count_matches(df, strs, all = TRUE)
count_matches(df, strs, all = TRUE, detail = TRUE)
count_matches(df, strs, detail = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.