I have a character vector with timestamps like the following:
Date <- c("Jul 31, 2017", "Jul 30, 2017", "Jul 29, 2017", "Jul 28, 2017")
And I'm trying to convert it into a date object type. I have tried several methods:
as.Date
Date <- as.Date(Date, format = "%B %d, %Y")
strptime
Date <- strptime(Date, format = "%B %d, %Y")
mdy from lubridate
Date <- mdy(Date)
But all of them returns NAs. I have also tried changing the format argument from %B
to %b
and the result is the same. Moreover, with mdy
from lubridate
parses the data in a different format than I'm expecting to. For example, if I do the run the next piece of code:
mdy("Jul 01, 2017")
I get as a result:
[1] "2017-01-20"
What can I do to convert it to a date in the proper format? Thank you.