How to emulate SQLs rank functions in R? How to emulate SQLs rank functions in R? r r