0

I have problems sorting data by month and year. I'm using as.yearmon() as shown here. However, some months are not recognized by as.yearmon function (march, mai, october, december). I found out that using German abbreviations instead of English abbreviations works fine, for example Dez instead od Dec. Also tried caps and no caps. It seems to by a default setting or I miss a command in the as.yearmon function. Ideas?? Here some sample data:

dat <- c("2009-Sep","2009-Feb","2009-Jan","2009-Oct")
require(zoo)
d2 <- as.yearmon(dat, "%Y-%b")
sort(d2)

In this case I lose the last entry 2009-Oct and I don't know why. My output is only:

"Jan 2009" "Feb 2009" "Sep 2009"

However, using this (note Okt instead of Oct, german style):

dat <- c("2009-Sep","2009-Feb","2009-Jan","2009-Okt")

I get the wright output. Do you have ideas how to solve this problem? Thanks

Community
  • 1
  • 1
N.Varela
  • 910
  • 1
  • 11
  • 25

1 Answers1

1

You possibly need to change the locale settings:

 Sys.setlocale("LC_TIME", "C")

If that does not work you can start R with "LANG="C"

Community
  • 1
  • 1
Bulat
  • 6,869
  • 1
  • 29
  • 52