I'm trying to sort a vector with year and month information. I'm getting year and month from a Date type variable. Here's an example of what I'm trying to accomplish:
example <- as.Date(c("2010-04-22", "2010-04-26", "2010-04-26",
"2010-06-04", "2010-06-07", "2010-06-18", "2010-06-21",
"2010-07-14", "2010-07-16", "2010-07-30", "2010-08-20"))
mes_ano <- as.character(as.yearmon(as.Date(example)))
mes_ano <- factor(mes_ano, levels = c(unique(mes_ano),
"mai 2010", "set 2010", "out 2010", "nov 2010"))
Now I would like to sort mes_ano by year and month, but I don't know how.
Actually, my real goal is to sort the levels, since I'll make a plot with ggplot2 and I need the levels to be sorted. But I thought that it would make our life easier if I just asked about sorting a vector. Then I can figure out how to sort levels.