mode_by_group <- function(x) unique(x)[which.max(table(x)[table(x)>0)]
DT[ , moda := myfun(number), by = age]
DT
age v number moda
1: 12 -0.9740026 122 122
2: 12 0.6893727 125 122
3: 3 -0.9558391 5 5
4: 3 -1.2317071 5 5
5: 12 -0.9568919 122 122