I'm new to R. My data has 600k objects defined by three attributes: Id
, Date
and TimeOfCall
.
TimeofCall
has a 00:00:00
format and range from 00:00:00
to 23:59:59
.
I want to bin the TimeOfCall
attribute, into 24 bins, each one representing hourly slot (first bin 00:00:00
to 00:59:59
and so on).
Can someone talk me through how to do this? I tried using cut()
but apparently my format is not numeric. Thanks in advance!
You can use
cut.POsixlt
function. But you should coerce your data to a valid time object. here I am using handyhms
fromlubridate
. Andstrftime
to get the time format.While you could convert to a formal time representation, in this case it might be easier to just use
substr
:Using a
POSIXct
time to deal with it would also work, and might be handy if you plan on further calculations (differences in time etc):