Test if a vector contains a given element

后端 未结 7 1376
慢半拍i
慢半拍i 2020-11-22 02:40

How to check if a vector contains a given value?

相关标签:
7条回答
  • 2020-11-22 03:00

    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
    
    0 讨论(0)
提交回复
热议问题