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,635
  • 1
  • 16
  • 31
codercc
  • 89
  • 7
  • 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
  • 176
  • 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]
sindri_baldur
  • 25,109
  • 3
  • 30
  • 57