Finding ALL duplicate rows, including “elements with smaller subscripts”

后端 未结 7 731
借酒劲吻你
借酒劲吻你 2020-11-21 07:55

R\'s duplicated returns a vector showing whether each element of a vector or data frame is a duplicate of an element with a smaller subscript. So if rows 3, 4,

7条回答
  •  时光说笑
    2020-11-21 08:30

    You need to assemble the set of duplicated values, apply unique, and then test with %in%. As always, a sample problem will make this process come alive.

    > vec <- c("a", "b", "c","c","c")
    > vec[ duplicated(vec)]
    [1] "c" "c"
    > unique(vec[ duplicated(vec)])
    [1] "c"
    >  vec %in% unique(vec[ duplicated(vec)]) 
    [1] FALSE FALSE  TRUE  TRUE  TRUE
    

提交回复
热议问题