Suppose I have a dataframe:

```
df=data.frame(cat=c("b1","b2","b3","b2","b5","b1","b3"),
              item=c("a1","a2","a3","a4","a1","a3","a4"),
              status=c("ok","good","bad","excellent","ok","good","bad"))

```

And I need for each category b1-b5, choose only the top a (ranked by status from excellent to good to ok to bad) and corresponding status, and in case of tie take a random one.

So for b1 it'll take a3 good instead of a1 ok, for b3 it could take either a3 bad or a4 bad. sample output:

```
  cat item    status
  b1   a3     good

```

What's the best way to do this?