I want to count how many rows are equal to the max value within a group (in data.table). I know from Select the row with the maximum value in each group how to find the max value in data.table.
set.seed(5)
z <- data.table( data.frame(
group=( sample( letters[1:5], 25, replace=T) ),
size=( sample( 1:5, 25, replace=T) )))
z <- z[ order( group, size ), ]
z[ , maxsize := max(size), by = .(group)]
So in this example, I want a column equal to 2 for group a, (since there are two observations equal to 3) and 4 for b, 2 for c etc.