I have the following Problem: I have a dataset including 3 different columns (there are more, but for the analysis they are not relevant). Here is an example Dataset (the origin dataset has much more observations):
Date Company Return
March A 0.03
March A 0.02
March B 0.01
April B 0.02
April A 0.01
May C 0.02
June B 0.03
Now I want to find the biggest return for every month, but each company should show 3 times at max in the final output. I tried some for loops to create subsets for each month, but then I have no idea how I can extract the biggest return for each month while still have the restriction of each company showing up less than 3 times. Important is that when a company was returned three times in the output, the company with the next highest return has to be picked for the certain month. Every month hast to be returned one time.