user5036080 user5036080 - 3 years ago 99
R Question

Converting column from military time to standard time

I'm trying to convert a column showing the time of road traffic accidents from military time to standard time. The data looks like this:

Col1 Time..24hr.
1 1404
2 322
3 1945
4 1005
5 945


I'd then like to convert to 12hr so for '322' I'd like to make '3', for instance. Thanks a lot

Answer Source

Given your criteria -- that 322 is represented as 3 and 2045 is 20 -- how about dividing by 100 and then rounding towards 0 with trunc().

 time_24hr <- c(1404, 322, 1945, 1005, 945)
 trunc(time_24hr / 100)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download