library(dplyr)
df <- tibble(
customer = c("Mike", "Mike", "John", "Pedro", "Bill", "Tim"),
old_address = rep(c("P", "Q"), each = 3),
correct_address = rep(c("X", "Y"), each = 3)
)
df
#> # A tibble: 6 x 3
#> customer old_address correct_address
#> <chr> <chr> <chr>
#> 1 Mike P X
#> 2 Mike P X
#> 3 John P X
#> 4 Pedro Q Y
#> 5 Bill Q Y
#> 6 Tim Q Y
How can I mutate total distinct number of customer
who are still reporting old_address
?
Here is my desired output:
# A tibble: 2 x 3
old_address correct_address distinct_customer
<chr> <chr> <dbl>
1 P X 2
2 Q Y 3