Вот решение с использованием dplyr
.
library(dplyr)
## make some dummy data
df <- tribble(
~distributor, ~something,
"dist1", 89,
"dist2", 92,
"dist3", 29,
"dist1", 89
)
df %>%
group_by(distributor) %>%
## this counts the number of occurences of each distributor
mutate(occurrences = n()) %>%
ungroup() %>%
## change the name of the distributor if the occurrences are less than 2
mutate(distributor = ifelse(occurrences < 2, "small company", distributor))