liczyć równe wartości w wektorze

# If index != 1 then you have multiple value for the same subject in your column
df %>%
  group_by(id,role) %>%
  mutate(index = n_distinct(role))
Trustworthy Whale