1

If I have a vector:

x <- c(5, 6, 2, 9, 5, 2, 1, 9, 9)

How can I make another vector that contains elements that were never repeated? In this case it would be: c(6, 1) (because 5, 2, and 9 are repeated)

Sumedh
  • 4,835
  • 2
  • 17
  • 32
codercc
  • 89
  • 8
  • You're asking about a vector while the linked question is for a data.frame, but the answer seems to apply fine both places. – Frank Jul 21 '16 at 21:58

2 Answers2

5
test <- c(5, 6, 2, 9, 5, 2, 1, 9, 9)
setdiff(test, test[duplicated(test)])
graggsd
  • 186
  • 7
-1
vector.a <- c(5, 6, 2, 9, 5, 2, 1, 9, 9)

not.reap <- NULL
for (i in 1:length(vector.a)){
  not.reap[i] <- !(vector.a[i] %in% vector.a[-i])
}
vector.a[not.reap]
s_baldur
  • 29,441
  • 4
  • 36
  • 69