1

I am having the data set filtered from from other data base, which is as below

        Date| freq
____________|_________
 01-Aug-2017| 3079
 02-Aug-2017| 3239
 03-Aug-2017| 3026
 04-Aug-2017| 2700
 05-Aug-2017|  846
 05-Jul-2017| 2647
 06-Aug-2017|  579
 07-Aug-2017| 3145
 08-Aug-2017| 3386
 09-Aug-2017| 3350
 10-Aug-2017| 3127
 11-Aug-2017| 2824
 12-Aug-2017|  784
 12-Jun-2017| 2359
 13-Aug-2017| 575
 13-Jun-2017| 2074
 14-Aug-2017| 3258
 14-Jun-2017| 2022
 15-Aug-2017| 2948
 15-Jun-2017| 2143

Sorting is not happening as per the date, but as per the characters. I tried to convert the date format with as.Date but not successful. It will be a great help, to convert the date in any format and sort it date wise. Any support in this direction will be a great help.

Thanks, Praveen

5
  • Please show us the code that you are trying Commented Oct 11, 2017 at 8:59
  • Try somethinkg like yourData$newDates <- as.Date(yourData$Date, "%d-%b-%Y") Commented Oct 11, 2017 at 9:08
  • Or just yourData[order(as.Date(yourData$Date, format = "%d-%b-%Y")), ] Commented Oct 11, 2017 at 9:18
  • 1
    Possible duplicate of How to sort a data frame by date Commented Oct 11, 2017 at 9:19
  • Thanks for your support.. this has helped a lot :) Commented Oct 11, 2017 at 11:42

1 Answer 1

1

Let assume your dataframe is named 'd' Apply code to sort according to dates:

d[order(as.Date(d$V3, format="%d/%m/%Y)),]
Sign up to request clarification or add additional context in comments.

2 Comments

In this case, we need to use format = "%d-%b-%Y" instead of format = "%d/%m/%Y". This can help to understand the specification of dates format.
Yes in the above case we can use "%d-%b-%Y" format.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.