The key is to start grouping by both a and b to compute the frequencies and then take only the most frequent per group of a, for example like this:
df %>%
count(a, b) %>%
slice(which.max(n))
Source: local data frame [2 x 3]
Groups: a
a b n
1 1 B 2
2 2 B 2
Of course there are other approaches, so this is only one possible "key".