Test if a vector contains a given element

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

How to check if a vector contains a given value?

7条回答
  •  悲哀的现实
    2020-11-22 02:51

    Also to find the position of the element "which" can be used as

    pop <- c(3,4,5,7,13)
    
    which(pop==13)
    

    and to find the elements which are not contained in the target vector, one may do this:

    pop <- c(1,2,4,6,10)
    
    Tset <- c(2,10,7)   # Target set
    
    pop[which(!(pop%in%Tset))]
    

提交回复
热议问题