0

The idea is not removing one of the duplicate rows but all repeated rows.

Data that I Have now

Name Score
AB 75
AB 75
BC 50
CD 70

Expected Result

Name Score
BC 50
CD 70
Roshan
  • 79
  • 6

2 Answers2

1

One option is to use group_by to detect the combinations of variables with duplicates and filter based on group size.

library(tidyverse)
#> Warning: package 'readr' was built under R version 4.1.2
withdups <- data.frame(
  stringsAsFactors = FALSE,
              Name = c("AB", "AB", "BC", "CD"),
             Score = c(75L, 75L, 50L, 70L)
)

withdups %>% 
  group_by(Name, Score) %>% 
  filter(n() == 1)
#> # A tibble: 2 x 2
#> # Groups:   Name, Score [2]
#>   Name  Score
#>   <chr> <int>
#> 1 BC       50
#> 2 CD       70

Created on 2022-04-12 by the reprex package (v2.0.1)

Emily Kothe
  • 842
  • 1
  • 6
  • 17
0
library(tidyverse)
withdups %>%
add_count(Name, Score) %>%
filter(n == 1)
Lennyy
  • 5,932
  • 2
  • 10
  • 23