mutate the data frame if a duplicate is found

Does this work:

> df4 %>% group_by(!!sym(EMP_ID)) %>%
+   mutate(`Duplicate_id` = ifelse(duplicated(!!sym(EMP_ID)),"00. id duplicated",''))
# A tibble: 16 x 3
# Groups:   emp_id [14]
   emp_id   email                   Duplicate_id     
   <fct>    <fct>                   <chr>            
 1 DEV-2962 [email protected]      ""               
 2 KTN_2252 [email protected]    ""               
 3 ANA2719  [email protected]   ""               
 4 ITI_2624 [email protected]        ""               
 5 DEV2698  [email protected]         ""               
 6 HRT2921  [email protected]     ""               
 7 ""       [email protected]       ""               
 8 KTN2624  [email protected]    ""               
 9 DEV2698  [email protected]   00. id duplicated
10 ITI2535  [email protected] ""               
11 DEV2698  [email protected]     00. id duplicated
12 HRT2837  [email protected]      ""               
13 ERV2951  [email protected]   ""               
14 KTN2542  [email protected]  ""               
15 ANA2813  [email protected]    ""               
16 ITI2210  [email protected]  ""               
> 

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top