1

I found here a simple way to convert String to date format. The problem is I get different result in comparision with those on the website.

sdate1 <- "6aug2005"
sdate2 <- "jan151999"
sdate3 <- "12-15-2001"

ndate1 <- as.Date(sdate1, "%d%B%Y"); ndate1
ndate2 <- as.Date(sdate2, "%B%d%Y"); ndate2
ndate3 <- as.Date(sdate3, "%m-%d-%Y"); ndate3

sdate1 <- "6aug2005"
sdate2 <- "jan151999"
sdate3 <- "12-15-2001"

ndate1 <- as.Date(sdate1, "%d%B%Y"); ndate1
[1] NA
ndate2 <- as.Date(sdate2, "%B%d%Y"); ndate2
[1] NA
ndate3 <- as.Date(sdate3, "%m-%d-%Y"); ndate3
[1] "2001-12-15"

So only the third way works correctly? Any idea way it doesn't work and how to fix it?

My sessionInfo()

R version 3.1.3 (2015-03-09)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=Polish_Poland.1250  LC_CTYPE=Polish_Poland.1250    LC_MONETARY=Polish_Poland.1250
[4] LC_NUMERIC=C                   LC_TIME=Polish_Poland.1250    

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

loaded via a namespace (and not attached):
[1] tools_3.1.3
nrussell
  • 18,382
  • 4
  • 47
  • 60
jjankowiak
  • 3,010
  • 6
  • 28
  • 45

0 Answers0