How to order by date in R?



Hi everyone,

I am new to data science and would be needing your help on an issue. I was working on Bike Sharing problem and wanted to sort my rows on the basis of date.

Actually the data set is such that data for first nineteen days of every month for 2 years is given in the training set, and the data for days from 20th of the month to the end of the month for the same 2 years is present in the test data set.
When I merged the 2 datasets using

the dates got shuffled up.

Now I want to order my rows such that data for 20th day comes after the 19th day of the month and so on.
Please suggest some method to implement this.

Thanks in advance!


Did you try order function?
Also check out arrange in dplyr package


I wasn’t able to achieve the required results using them. Please correct me if I have used something wrong.


This did not give the required results.


hey there,

can you write down the sample dataset along with the output of class(total$datetime). I may be able to help as I did this problem a few months back.




The class of total$datetime is “factor”.

A snapshot of the dataset canbe seen here.

For the actual data set:
train.csv (633.2 KB)



hi there,

Well this is how I want you to proceed with this.

Extract year,month and date from the datetime column.


Hope it helps !!



arrange in the library dplyr will do you work . i have used it some time back .