How to handle dates in the format of only month and year i.e."Aug-15" "Dec-16" ? One way is to adding day<-01 to the date in order to handel missing day part in Date .and reading it as as.date. Or you can be smart and install the "zoo" package.
# Use the package zoo # install.packages("zoo") library(zoo)
Lets try sorting some dates in month year format (i.e. format="%b-%y").
Date=c("Apr-15", "Apr-16", "Aug-15", "Dec-15" , "Feb-15", "Feb-16", "Jan-16"); str(Date)
## chr [1:7] "Apr-15" "Apr-16" "Aug-15" "Dec-15" "Feb-15" ...
Read the dates in Date which are in character using as.yearmon function from zoo.
sort(as.yearmon(Date,format="%b-%y"))
## [1] "Feb 2015" "Apr 2015" "Aug 2015" "Dec 2015" "Jan 2016" "Feb 2016" ## [7] "Apr 2016"
Have Fun