Fastest way to remove all duplicates in R

前端 未结 3 1826
不思量自难忘°
不思量自难忘° 2020-12-10 14:04

I\'d like to remove all items that appear more than once in a vector. Specifically, this includes character, numeric and integer vectors. Currently, I\'m using duplica

3条回答
  •  一向
    一向 (楼主)
    2020-12-10 14:45

    You could use a set operation:

    d <- c(1,2,3,4,1,5,6,4,2,1)
    duplicates = d[duplicated(d)]
    setdiff(d, duplicates)
    [1] 3 5 6
    

    (Not certain if that is more efficient than the above code but it does seem conceptually cleaner)

提交回复
热议问题