Difference between two vectors in R

前端 未结 2 863
盖世英雄少女心
盖世英雄少女心 2020-12-29 20:48

I have two vectors:

a <- c(1, 1, 3, 4, 5, 7, 9)
b <- c(2, 3, 4, 6, 8, 2)

I want to find the numbers in the second vector, which are n

相关标签:
2条回答
  • An alternative way, instead of setdiff (which is probably preferrable), is to use %in%

    unique(b[! b %in% a])
    #[1] 2 6 8
    
    0 讨论(0)
  • 2020-12-29 21:14

    You can use setdiff

    setdiff(b,a)
    #[1] 2 6 8
    
    0 讨论(0)
提交回复
热议问题