as.POSIXct not working for all dates with same format

30 views Asked by At

With these data:

Dat <- structure(list(IndID = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L
), .Label = "BHS_017_A", class = "factor"), DateTimeUTC = structure(1:7, .Label = c("2015.03.07 06:00:36", 
"2015.03.07 11:00:49", "2015.03.07 16:00:36", "2015.03.07 21:00:41", 
"2015.03.08 02:00:36", "2015.03.08 07:00:36", "2015.03.08 12:00:36"
), class = "factor")), .Names = c("IndID", "DateTimeUTC"), row.names = c(NA, 
-7L), class = "data.frame")

I am using the following code to convert dates to POSIXct dates.

Dat$Time <- as.POSIXct(strptime(as.character(Dat$DateTimeUTC),"%Y.%m.%d %H:%M:%S"))

However, when looking at the output below, an NA is generated for one of the the time values with what looks like the exact same format. What am I missing here?

This is occurring a number of places in my dataframe but I have only posted a small reproducible example here.

head(Dat)

      IndID         DateTimeUTC                Time
1 BHS_017_A 2015.03.07 06:00:36 2015-03-07 06:00:36
2 BHS_017_A 2015.03.07 11:00:49 2015-03-07 11:00:49
3 BHS_017_A 2015.03.07 16:00:36 2015-03-07 16:00:36
4 BHS_017_A 2015.03.07 21:00:41 2015-03-07 21:00:41
5 BHS_017_A 2015.03.08 02:00:36                <NA>
6 BHS_017_A 2015.03.08 07:00:36 2015-03-08 07:00:36
0

There are 0 answers