strptime returning NA values [closed]

≯℡__Kan透↙ 提交于 2019-12-27 01:21:30

问题


I'm trying to use strptime to format dates I'm reading in but only get NA values are returned in the output.

My raw data is in the format of 1974-01-01, and the length of the dataset is 12049 so the last date is 2006-12-31.

The code I use is:

Data$date.yyyymmdd <- as.POSIXct(strptime(Data$date.yyyymmdd, format = "%d/%m/%Y"))

Any help or insight into this problem would be very much appreciated!


回答1:


The format argument you give should reflect the format that the data is currently in, not the format that you want to convert it to, so you would have to set format = "%Y-%m-%d". Read the documentation on strptime again and it should make sense.



来源:https://stackoverflow.com/questions/30622236/strptime-returning-na-values

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