I would like to filter out ID's which do not share the same 'place' value. So that in provided example I get just IDs A & C. I'll aprreacite your help.
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
data <- tibble(ID = c("A", "A", "B", "B", "C"),
place = c("London", "London", "Berlin", "Prague", "Madrid"))
library(tidyverse)
data <- tibble(ID = c("A", "A", "B", "B", "C"),
place = c("London", "London", "Berlin", "Prague", "Madrid"))
data |>
distinct() |>
group_by(ID) |>
filter(n() == 1) |>
ungroup()
#> # A tibble: 2 × 2
#> ID place
#> <chr> <chr>
#> 1 A London
#> 2 C Madrid