I'd like to add a (dense) rank column to my dataframe based on multiple other columns, like rank() over (order by a, b) in SQL. In R, the rank function only accepts one column, so mutate(df, rank(a, b)) throws an error. The order_by function also only accepts one column.
So given this data frame:
d <- data.frame(a = c(1, 1, 1, 2), b = c(1, 1, 2, 2))
...I'd like a rank like the following:
a b rank
1 1 1
1 1 1
1 2 2
2 2 3
My actual dataframe is much larger and the ranking needs to be over multiple columns of different types (mostly strings and doubles).