测试向量是否包含给定元素 [英] Test if a vector contains a given element
本文介绍了测试向量是否包含给定元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检查向量是否包含给定值?
How to check if a vector contains a given value?
推荐答案
match()
(返回第一次出现)和%in%
(返回布尔值)都是为此设计的.
Both the match()
(returns the first appearance) and %in%
(returns a Boolean) functions are designed for this.
v <- c('a','b','c','e')
'b' %in% v
## returns TRUE
match('b',v)
## returns the first location of 'b', in this case: 2
这篇关于测试向量是否包含给定元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文