Find time difference in days with R

寵の児 提交于 2020-01-06 20:06:46

问题


Does anyone have a clue why in the following code I get "Time difference of NA secs" result? I was expecting to get the difference of days, like the It did for "2015-01-06".

today <- Sys.Date()
today <- strptime(today, "%Y-%m-%d")
date <- "2015-01-06"
date <- strptime(date, "%Y-%m-%d")
today - date
Time difference of 321 days

Well done. But then...

date <- "2015-10-18"
date <- strptime(date, "%Y-%m-%d")
today - date
Time difference of NA secs

Why secs?

EDIT: Here is session info

R version 3.2.1 (2015-06-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)

locale:
[1] LC_COLLATE=Portuguese_Brazil.1252  LC_CTYPE=Portuguese_Brazil.1252   
[3] LC_MONETARY=Portuguese_Brazil.1252 LC_NUMERIC=C                      
[5] LC_TIME=Portuguese_Brazil.1252    

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

loaded via a namespace (and not attached):
[1] tools_3.2.1

来源:https://stackoverflow.com/questions/33878552/find-time-difference-in-days-with-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!