Search code examples
rdateformatnastrptime

strptime returning NA values


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!


Solution

  • 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.