在第二个向量中找到一个向量值的所有匹配项的所有位置 [英] Find all positions of all matches of one vector of values in second vector
本文介绍了在第二个向量中找到一个向量值的所有匹配项的所有位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要找到向量中与另一个向量的任何值相对应的所有位置:
I need to find all positions in my vector corresponding to any of values of another vector:
needles <- c(4, 3, 9)
hay <- c(2, 3, 4, 5, 3, 7)
mymatches(needles, hay) # should give vector: 2 3 5
是否有任何允许执行此操作的预定义功能?
Is there any predefined function allowing to do this?
推荐答案
这应该有效:
which(hay %in% needles) # 2 3 5
这篇关于在第二个向量中找到一个向量值的所有匹配项的所有位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文