我有2个字符串向量,并且我已经将它们相交以获得相交的字符串向量,但是现在,我需要获得其他2个没有相交元素的字符串向量。
即,vector.1
没有intersected.vector
元素,vector.2
没有intersected.vector
元素。我怎么能这样做?
答案 0 :(得分:-1)
我希望这个简单的例子可以说明你的要求:
vector.1 <- LETTERS[1:4]
vector.2 <- LETTERS[3:6]
> vector.1
[1] "A" "B" "C" "D"
> vector.2
[1] "C" "D" "E" "F"
intersected.vector <- intersect(vector.1, vector.2)
> intersected.vector
[1] "C" "D"
new_vec1 <- vector.1[-which(vector.1 %in% intersected.vector)]
> new_vec1
[1] "A" "B"
new_vec2 <- vector.2[-which(vector.2 %in% intersected.vector)]
> new_vec2
[1] "E" "F"