I have the dataframe below:
product<-c("asd","saf","asd","bc","asd","saf","bc","saf")
date<-as.Date(c("2018-07-29","2018-07-25","2018-07-28","2018-06-29","2018-07-21","2018-07-12","2018-02-28","2018-07-10"))
p<-data.frame(product,date)
What I want to achieve is sort this dataframe by product name firstly and then by date without ruining the initial sorting.
I use:
p <- p %>% arrange(product)
to sort by name but when I use:
p<-p[order(as.Date(p$date, format="%Y/%m/%d")),]
the name sorting is lost.
An acceptable solution would be:
product date
1 asd 2018-07-25
2 asd 2018-07-28
3 asd 2018-07-29
4 saf 2018-02-28
5 saf 2018-06-29
6 saf 2018-07-10
7 bc 2018-02-28
8 bc 2018-07-12
as I do not care about alphabetical sorting between names.