0

I am having a problem to format the date of my research files. I just give a simple example which works in the book of "The R book", but not for me:

x <- c("00aug", "01sep", "99sep")
strptime(x, "%y%b")
[1] NA NA NA

the result, according to my understanding, should be something like "2000-08-01", "2001-09-01" and "1999-09-01", but they all came to NA ... I also tried to set the environment like this, but also doesn't work.

Sys.setlocale(locale = "ENGLISH")

This is my sessionInfo():

> sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_3.6.3

Can anyone help me out? Have been struggle into this problem for two days...

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
Marco
  • 505
  • 9
  • 18
  • 1
    You're `x` is missing the day. If you want the first day of the month, then try: `strptime(paste0(x, "01"), "%y%b%d")`. – Edward Jul 16 '20 at 02:30
  • Thanks Edward for the prompt answer. Also thank Ben for linking my question to others, and sorry for the repeated question. I have tried to search for similar questions, but didn't find these... Will do more work next time. – Marco Jul 16 '20 at 02:39

0 Answers0