-1

I have this date column of form:

20160812
20160813

Basically YYYYMMDD.

I converted it to a date using strptime and as.Date

weather_dataset$DATE = as.Date(weather_dataset$DATE,"%Y%m%d")

But I get

Error in charToDate(x) : 
  character string is not in a standard unambiguous format

Huh? I've clearly specified the format to use, but its still throwing me this error for some reason. Would appreciate help! :)

Thank you!

J_F
  • 9,956
  • 2
  • 31
  • 55
Wboy
  • 2,452
  • 2
  • 24
  • 45
  • or [R read dates in format yyyymmdd](http://stackoverflow.com/questions/18116388/r-read-dates-in-format-yyyymmdd) – Ronak Shah Nov 10 '16 at 13:21

2 Answers2

4

Your data has to be a character. So use this workaround:

weather_dataset$DATE <- as.Date(as.character(weather_dataset$DATE),"%Y%m%d")

Another possibility is the library(lubridate):

weather_dataset$DATE <- lubridate::ymd(weather_dataset$DATE)
J_F
  • 9,956
  • 2
  • 31
  • 55
2
library(anytime)

anydate(20160812)
Henk
  • 3,634
  • 5
  • 28
  • 54