I have the following situation:
vec1 <- c("A", "B", "D", "C", "E", "A", "C")
vec2 <- c("A", "B", "C", "D", "F")
First question: which one is duplicated ? - answer "A" and "C" for vec1, 0 for vec2
Second question: Identify which is vec1 but not in vec2, irrespective of order (answer "E")
or vice versa (answer "F")
which(vec1 !=vec2)
which(vec2 !=vec1)
[1] 3 4 5 7
Warning message:
In vec1 != vec2 :
longer object length is not a multiple of shorter object length
which is not what I expected....
For the first question, try ?duplicated
vec1.dup <- duplicated(vec1)
unique(vec1[vec1.dup])
[1] "A" "C"
For the second, try ?setdiff
. You want the values of vec2 that are not in vec1.
setdiff(vec2, vec1)
[1] "F"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With