We could get the 'Mode' of 'b' grouped by 'a' using ave
Mode <- function(x) {
ux <- unique(x)
ux[which.max(tabulate(match(x, ux)))]
}
df$c <- with(df, ave(b, a, FUN=Mode))
df$c
#[1] 2 2 2 2 3 3 3 1 1
Or using data.table
library(data.table)
setDT(df)[, c:= Mode(b), by=a][]