I have a data frame with 2 columns: 'sales' and 'month'. I want to add a column that ranks the sales within each month. Does anyone know what's the most succinct way of doing so? I'm thinking of 'tapply' but it gives me a list and I can't add it back to the data frame (easily or succinctly).
Sales Month Rank
100 1 3
200 2 1
300 3 1
150 1 2
220 1 1
100 is third place amongst sales that belong to month 1 while 220 is first place for month 1.