Find duplicated elements with dplyr

后端 未结 5 1342
花落未央
花落未央 2020-12-04 11:06

I tried using the code presented here to find ALL duplicated elements with dplyr like this:

library(dplyr)

mtcars %>%
mutate(cyl.dup = cyl[duplicated(cyl         


        
5条回答
  •  既然无缘
    2020-12-04 11:44

    We can find duplicated elements with dplyr as follows.

    library(dplyr)
    
    # Only duplicated elements
    mtcars %>%
      filter(duplicated(.[["carb"]])
    
    # All duplicated elements
    mtcars %>%
      filter(carb %in% unique(.[["carb"]][duplicated(.[["carb"]])]))
    

提交回复
热议问题