The dplyr package does this with intuitive, readable code.
Here's a toy example, taking rows from mtcars
where there are no duplicated values of cyl
and gear
:
library(dplyr)
mtcars %>%
group_by(cyl, gear) %>%
filter(n() == 1) %>%
ungroup()
Source: local data frame [2 x 11]
mpg cyl disp hp drat wt qsec vs am gear carb
(dbl) (dbl) (dbl) (dbl) (dbl) (dbl) (dbl) (dbl) (dbl) (dbl) (dbl)
1 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3 1
2 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6
Those two combinations of cyl and gear are the only unique ones, which you can confirm with:
mtcars %>%
count(cyl, gear)