| count_values {tablecompare} | R Documentation |
Check for existence of multiple values per group
Description
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.
Usage
count_values(.data, col, by, setkey = FALSE)
assert_single_value(.data, col, by)
Arguments
.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 |
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))
## Not run:
assert_single_value(df, z, by = c(x, y))
## End(Not run)