Finding the number of unique elements in two vectors in R

后端 未结 3 1850
后悔当初
后悔当初 2021-01-27 11:31

I\'m working with two \'lists\' or vectors in R, and I need to find out the number of unique elements in both, together.

I tried doing length(summary(merge(v1, v2

相关标签:
3条回答
  • 2021-01-27 11:39

    It sounds like you're looking for union:

    > union(v1, v2)
    [1]  1  2  3  4  5  6 10 11
    
    0 讨论(0)
  • 2021-01-27 11:41

    here is my solution.

    p1 <- c(1, 4, 1, 1, 4, 5, 6, 7, 8)
    p2 <- c(3, 4, 1, 6, 90, 10, 32)
    unique(c(p1, p2))
    
    0 讨论(0)
  • 2021-01-27 11:57

    You can use unlist with union

        unlist(union(a,b))
    
    0 讨论(0)
提交回复
热议问题