I have a table
ID RATES
1 0.01
1 0
1 0
1 0
2 0.05
2 0.05
2 0.01
2 0
3 0
3 0
3 0
Ideally, I want to create a new column called n_rates which replace the 0 values in rate column by group (ID) and conditions.
Condition 1 - If at least one rate IN (0.01, 0.015, 0.05) for this ID THEN replace all 0 values by the most rate values (e.g. if for this ID, 0.01 appears more than 0.05 then replace 0 with 0.01. Only rates == 0 rows can be replaced)
Condition 2 - If rates NOT IN (0.01, 0.015, 0.05) then make no changes to the rows