0

This seems like something very basic, but unique and distinct functions dont work in this case.

a <- as_tibble(c(1,1,2,2,3,4,4,5))
a
# A tibble: 8 x 1
  value
  <dbl>
1     1
2     1
3     2
4     2
5     3
6     4
7     4
8     5

The result should be a tibble, where i only have values, that dont appear more than one time, like this:

# A tibble: 8 x 1
  value
  <dbl>
1     3
2     5

I tried unique and distinct, but that ofcourse gives me:

# A tibble: 5 x 1
  value
  <dbl>
1     1
2     2
3     3
4     4
5     5

which is not what i want.

Dutschke
  • 277
  • 2
  • 15

1 Answers1

1

Using base R, this is indeed a bit ugly. :) Notice that example you provided differs from the printed text.

xy <- data.frame(value = c(1,1,2,2,3,4,4,5))

un <- table(xy$value)
un <- un[un == 1]
xy[xy$value %in% names(un), , drop = FALSE]

  value
5     3
8     5
Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197