I have a local.time column in my data frame of class character containing elements like this :
> a$local.time
[1] "1:30 AM" "6:29 AM" "6:59 AM" "9:54 AM" "10:14 AM" "10:34 AM" "12:54 PM" "1:15 PM" "1:20 PM"
[10] "1:20 PM" "2:15 PM" "2:15 PM" "4:23 AM" "6:28 AM" "2:45 PM" "3:08 PM" "3:23 PM" "3:58 PM"
I wanted to convert them from class character to time variables. So I used:
> as.POSIXct(a$local.time, tz = "", format = "%I:%M %p", usetz = FALSE)
This resulted in :
[1] "2014-10-31 01:30:00 EDT" "2014-10-31 06:29:00 EDT" "2014-10-31 06:59:00 EDT" "2014-10-31 09:54:00 EDT"
[5] "2014-10-31 10:14:00 EDT" "2014-10-31 10:34:00 EDT" "2014-10-31 12:54:00 EDT" "2014-10-31 13:15:00 EDT"
I have a date variable in a different column and the intention is to provide the capability of filtering by date and zooming on time bands to the minute in a dynamic dashboard.
I want to remove the date and time zone from a$local.time but keep it in a time format so the chronology is maintained i.e. 18:57 is the 19th hour and 57th minute of the day etc.
If I use
a$local.time <- format(a$local.time, "%Y-%m-%d %H:%M:%S", usetz = FALSE)
a$local.time <- strftime(a$local.time, format = "%H:%m")
,
the class changes to character ! What's the right approach?