I have a vector of date-times stored as character strings of format 'm/d/Y H:M', for example: '1/3/2008 12:45', called datetime
.
I'm converting them with the following line of code:
datetime = as.POSIXct(datetime, format = '%m/%d/%Y %H:%M', tz = 'America/Los_Angeles')
This works for the majority of them, but some, which are in the same format, fail and return NA.
when testing, I discovered that the following line successfully worked:
as.POSIXct('03/13/2016 01:45', format = '%m/%d/%Y %H:%M', tz = 'America/Los_Angeles')
but when I changed the digit in the hour place to a '2', it failed and returned NA:
as.POSIXct('03/13/2016 02:45', format = '%m/%d/%Y %H:%M', tz = 'America/Los_Angeles')
however, as.POSIClt worked with both strings. Also, running this code in the a browser instance of R (https://rdrr.io/snippets/) worked without a problem.
Because as.POSIXlt seemed to work, I tried to just using that and moving on. Unfortunately, as.POSIXlt does not seem to be supported within dplyr, and furthermore, when I used it outside of the other dplyr functions I was using, some strings which were successfully converted in POSIXlt format, were reporting as NA, even though they were not NA:
If anyone knows how to either solve this problem, or another way to convert the time codes that won't have these problems, preferably that will work inside dplyr piped functions, that would be awesome.