与语言R匹配以获取位置 [英] match with language R for getting the position
本文介绍了与语言R匹配以获取位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用match获取元素是否在列表中.例如,我的列表是:
I am using match for getting if an element is in a list. For example my list is:
c("a","b","h","e"...) and so on
如果我想查看元素h是否在列表中,我将以这种方式使用match:
if I want to see if element h is in the list I am using match in this way:
if ("h" %in% v){do something}
如何获取在列表中找到元素的位置? 谢谢
How I can get the position of where it finds the element in the list? Thanks
推荐答案
如果您想知道位置,请使用which
If you want to know the position use which
l <- c("a","b","h","e")
which(l=='h')
[1] 3 # It'll give you the position, 'h' is the third element of 'l'
请注意,l
是向量,而不是您提到的列表.
Note that l
is a vector, not a list as you mentioned.
这篇关于与语言R匹配以获取位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文