Skip to content

IDate Error #1354

Closed
Closed
@geneorama

Description

I have a data set with an invalid time stamp, someone put in 14:00 PM.

Normally this converts to NA with IDate, but I found that in some instances it throws an error.

Reproducible example:

library(data.table)

v1 = c("07:36:00", "08:26:00", "08:50:00", "07:05:00", "07:37:00", "08:31:00", 
      "09:41:00", "10:21:00", "11:16:00", "12:05:00", "12:24:00", "12:43:00", 
      "12:52:00", "14:00:00")
v2 = c("AM", "AM", "AM", "AM", "AM", "AM", "AM", "AM", "AM", "PM", "PM", "PM", 
      "PM", "PM")
as.ITime(paste(v1, v2), format="%I:%M:%S %p")
paste(v1, v2)


as.IDate(c("03:00:00 AM", "03:00:00 PM", "15:00:00 AM", "14:00:00 PM"), "%I:%M:%S %p")
as.IDate(c("03:00:00 AM", "03:00:00 PM", "14:00:00 PM"), "%I:%M:%S %p")

"14:00:00 PM" == paste(v1, v2)[14]

Screen grab of what happens when I run the above example:
image

Session Info:

> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 7 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] data.table_1.9.6

loaded via a namespace (and not attached):
[1] chron_2.3-47

Also..
Strangely if the vectors are inside a data.table, the data.table will let me convert the vectors to an IDate without an error, but then it won't let me use the data.table. The data table now has an error.

v1 and v2 inside a data.table
image

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions