I want to able to sort a dataset in the following way: String variable (ascending), date variable (descending) and string variable (ascending). The date variable was a POSIXt object which i converted into a date using (as.date()). I am able to sort based on the sting variables(both of which as in ascending) but unable to sort based on date, i get an error message stating that it not a vector or that I cannot use a - (minus) sign.
Asked
Active
Viewed 41 times
1 Answers
0
You can use desc()
from dplyr
library(dplyr)
data <- expand.grid(date = seq.Date(Sys.Date() - days(10), Sys.Date(), "days"),
string1 = diamonds$color %>% levels() %>% unique(),
string2 = diamonds$cut %>% levels() %>% unique()
)
data %>%
arrange(desc(date), string1, string2)

mnist
- 6,571
- 1
- 18
- 41