You must do this:
final= df %>% group_by(xxx,yyyy) %>% summarise(Topcomp=toString(Company[c(which(min(cnt)==cnt))])) ##Source: local data frame [2 x 3] ##Groups: xxx [?] ## ## xxx yyyy Topcomp ## <int> <int> <chr> ##1 1 1 aaa, bbb ##2 2 0 ddd
You got an error because which returned two values ββso that your subset of Company two values ββwhen summarise requires one value. toString is similar to paste with collapse="," in that it collapses the two values ββinto a comma-separated string.
Also, as Alistair pointed out in his comment on another answer, you don't need c and which , so this can be simplified:
final= df %>% group_by(xxx,yyyy) %>% summarise(Topcomp=toString(Company[min(cnt)==cnt]))
source share