Hi,
Is there an equivalent to order() in base R that works with data.frames that have an arbitrary number of columns
For example say I have a dataframe
df = data.frame(
col1 = c(1, 1, 2, 3),
col2 = c(2, 1,3, 4)
)
# I could get a heirarchical order using the `order` function
order(df$col1, df$col2)
#> [1] 2 1 3 4
# But what if i want to turn this into a function where we don't need to know the number of columns in advanced?
order_dataframe <- function(df){
# what goes here to produce the same output as the above call to `order`?
}
Created on 2022-09-12 by the reprex package (v2.0.1)