I really like the tidyverse's dplyr distinct function.
library(dplyr)
df <- tribble(~Name, ~Response, ~Obs_No, ~Freq,
'Ben', 1, 1, 1,
'Marie', 0, 2, 1,
'Josh', 1, 3, 2,
'Josh', 0, 3, 2,
'Ana', 0, 4, 3,
'Ana', 0, 4, 3,
'Ana', 1, 4, 3)
df %>%
distinct()
#> # A tibble: 6 x 4
#> Name Response Obs_No Freq
#> <chr> <dbl> <dbl> <dbl>
#> 1 Ben 1 1 1
#> 2 Marie 0 2 1
#> 3 Josh 1 3 2
#> 4 Josh 0 3 2
#> 5 Ana 0 4 3
#> 6 Ana 1 4 3
AND just to show other options under distinct
library(dplyr)
df %>%
distinct(Name, Response, .keep_all = TRUE)
#> # A tibble: 6 x 4
#> Name Response Obs_No Freq
#> <chr> <dbl> <dbl> <dbl>
#> 1 Ben 1 1 1
#> 2 Marie 0 2 1
#> 3 Josh 1 3 2
#> 4 Josh 0 3 2
#> 5 Ana 0 4 3
#> 6 Ana 1 4 3
df %>%
distinct(Name, Obs_No, .keep_all = TRUE)
#> # A tibble: 4 x 4
#> Name Response Obs_No Freq
#> <chr> <dbl> <dbl> <dbl>
#> 1 Ben 1 1 1
#> 2 Marie 0 2 1
#> 3 Josh 1 3 2
#> 4 Ana 0 4 3
Created on 2021-04-27 by the reprex package (v2.0.0)