I have been struggling to solve this apparently easy problem, I have a data frame with the following column names:
  names <-  c("2013-1", "2013-10", "2013-11", "2013-12", "2013-2", 
"2013-3", "2013-4", "2013-5", "2013-6", "2013-7", "2013-8", "2013-9", 
"2014-1", "2014-2", "2014-3")
As you can see, the column names are dates (recognized by R as character) and I need to reorder the columns so each column corresponds to the month that comes after the previous one, eg. 2013-1, 2013-2, 2013-3... but since R sees the column names as words and not dates it is ordering it differently, with 2013-10 before 2013-2 for example.
I tried to convert the column names to date using:
as.Date(names, format="%Y-%m")
But R apparently does not recognize this date format and I get NA's. I am still stuck with this ordering no matter what I try so any help would be very appreciated.
Thank you