I have two columns x and y. I want to mark the first occurrence of a value that occurs either in x OR y.
library(dplyr)
tibble(x = c(1, 2, 2, 3, 7), y = c(7, 7, 8, 9, 10))
#> # A tibble: 5 × 2
#> x y
#> <dbl> <dbl>
#> 1 1 7
#> 2 2 7
#> 3 2 8
#> 4 3 9
#> 5 7 10
Created on 2021-11-15 by the reprex package (v0.3.0)
My expected output should look like:
#> # A tibble: 5 × 4
#> x y first_occurance_x first_occurance_y
#> <dbl> <dbl> <dbl> <dbl>
#> 1 1 7 T T
#> 2 2 7 T F
#> 3 2 8 F T
#> 4 3 9 T T
#> 5 7 10 F T
Created on 2021-11-15 by the reprex package (v0.3.0)