| count_values | R Documentation |
count_values() returns values of by variables for which the .data has
multiple unique rows, along with the number of unique rows for each
combination of values, only considering columns in col.
assert_single_value() throws an error if there are multiple unique rows for
any combination of by variable values, only considering columns in col.
count_values(.data, col, by, setkey = FALSE)
assert_single_value(.data, col, by)
.data |
A data frame or data table |
col |
tidy-select. Columns in |
by |
tidy-select. Columns in |
setkey |
Logical. Should the output be keyed by |
count_values()A data.table with the (filtered)
by columns and an additional column "n_vals" which shows the number of
unique rows in .data having the combination of by values shown
in the output row.
assert_single_value()No return value. Called to throw an error depending on the input.
df <- read.table(text = "
x y z
a 1 3
a 1 3
a 2 4
a 2 4
a 2 2
b 1 1
b 1 2
", header = TRUE)
count_values(df, z, by = c(x, y))
## Not run:
assert_single_value(df, z, by = c(x, y))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.