How to sort by year and month in R (using as.yearmon from zoo package)
问题 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