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.
Arguments
- .data
A data frame or data table
- col
tidy-select. Columns in
.data. When counting the number of unique rows, only the columns specified incolare considered.- by
tidy-select. Columns in
.data.- setkey
Logical. Should the output be keyed by
bycols?
Value
count_values()A
data.tablewith the (filtered)bycolumns and an additional column "n_vals" which shows the number of unique rows in.datahaving the combination ofbyvalues shown in the output row.assert_single_value()No return value. Called to throw an error depending on the input.
Examples
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))
#> x y n_vals
#> 1: a 2 2
#> 2: b 1 2
if (FALSE) {
assert_single_value(df, z, by = c(x, y))
}
