0

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.

VRK
  • 65
  • 4
  • Please produce a reproducible example https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Wietze314 Sep 26 '19 at 19:32

1 Answers1

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