Learn R Programming

validate (version 1.1.5)

is_unique: Test for uniquenes of records

Description

Test for uniqueness of columns or combinations of columns.

Usage

is_unique(...)

all_unique(...)

n_unique(...)

Value

For is_unique A logical vector that is FALSE for each record that has a duplicate.

For all_unique a single TRUE or FALSE.

For number_unique a single number representing the number of unique values or value combinations in the arguments.

Arguments

...

When used in a validation rule: a bare (unquoted) list of variable names. When used directly, a comma-separated list of vectors of equal length.

See Also

Other cross-record-helpers: contains_exactly(), do_by(), exists_any(), hb(), hierarchy(), is_complete(), is_linear_sequence()

Examples

Run this code

d <- data.frame(X = c('a','b','c','b'), Y = c('banana','apple','banana','apple'), Z=1:4)
v <- validator(is_unique(X, Y))
values(confront(d, v))

# example with groupwise test
df <- data.frame(x=c(rep("a",3), rep("b",3)),y=c(1,1,2,1:3))
v <- validator(is_unique(y, by=x))
values(confront(d,v))

Run the code above in your browser using DataLab