rdateas.date

function as.Date just recognizes german month - but not english month


I need to transform dates in R which have the format e.g. "01OCT2011". The Problem is that the function as.Date only considers German months. Here, I have an example:

> test <- c("15MAI2006","01OCT2011")
> test1 <- as.Date(test, format='%d%B%Y')
> test1
[1] "2006-05-15" NA 

"MAY" is in German "MAI". The function didn't get the date with the English spelling OCT.


Solution

  • If you are 'completely sure' that the language is German try this:

    Sys.setlocale("LC_ALL","German")
    
    test <- c("15MAI2006","01OKT2011")
    as.Date(test, format='%d%B%Y')
    
    [1] "2006-05-15" "2011-10-01"
    

    However, you have in your original data "01OCT2011" and October should be Okt