Filters a vector according to the number of duplicates in the vector, where the conditions for the acceptable number of duplicate values are specified.

dupe_thresh(invec, count)

Arguments

invec

The input vector.

count

The threshold for duplicates. See "Details".

Value

A vector.

Details

The "count" parameter can be either a single digit or a character vector showing the desired comparison to be used as the threshold (for example "> 5"). If no binary relational operator is specified, the relational operator used is >=.

References

http://stackoverflow.com/q/29973061/1270695

Author

Ananda Mahto

Examples

set.seed(1) x <- sample(letters[1:10], 35, TRUE) sort(table(x))
#> x #> c a b f g d i e j #> 2 3 3 3 3 4 5 6 6
table(dupe_thresh(x, 3))
#> #> a b d e f g i j #> 3 3 4 6 3 3 5 6
table(dupe_thresh(x, "<3"))
#> #> c #> 2
table(dupe_thresh(x, "== 3"))
#> #> a b f g #> 3 3 3 3
table(dupe_thresh(x, "!=3"))
#> #> c d e i j #> 2 4 6 5 6