Test if a vector contains a given element

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

How to check if a vector contains a given value?

7条回答
  •  误落风尘
    2020-11-22 02:46

    You can use the %in% operator:

    vec <- c(1, 2, 3, 4, 5)
    1 %in% vec # true
    10 %in% vec # false
    

提交回复
热议问题