R中两个向量之间的差异 [英] Difference between two vectors in R
本文介绍了R中两个向量之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个向量:
a <- c(1, 1, 3, 4, 5, 7, 9)
b <- c(2, 3, 4, 6, 8, 2)
我想在第二个向量中找到数字,但不在第一个向量中:
I want to find the numbers in the second vector, which are not in the first vector:
dif <- c(2, 6, 8)
我尝试了许多不同的方法(例如合并,不同类型(dplyr程序包),setdiff,比较(比较程序包)),但我仍然找不到解决方法。
I've tried many different approaches (such as merge, different types of joins (dplyr package), setdiff, compare (compare package)), but I still can't find a way to do it.
推荐答案
您可以使用 setdiff
setdiff(b,a)
#[1] 2 6 8
这篇关于R中两个向量之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文