| occurs {validate} | R Documentation |
For each row in a data frame, count how many similar rows there are. The
... argument is used to specify which variables are taken into
account. Missing values are counted as a unique value.
occurs(...)
... |
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. |
For each record it indicates how often the value or value combination in the arguments occur.
# for each element i the sequence (a,b,c,a,c,a)
# compute how often it occurrs in the sequence.
occurs(c("a","b","c","a","c","a"))
# for each record in 'iris' how often do the same
# (Sepal.Length, Species) combinations occur?
with(iris, occurs(Sepal.Length, Species))
# in the context of a validation. Check whether
# each individual Species occurs at least 10 times.
rules <- validator(occurs(Species) > 10)
cf <- confront(iris, rules)
summary(cf)