0

I've looked at similar questions but not been able to find an exact answer. I provide a reproducible example:

time_dataset<-c("10:40", "15:33", "02:12", "08:01", "13:15")

Currently the above variable is a character variable. However, I want it to be a time variable so that I can add and subtract times and use filters on time (e.g. am vs pm data)

How would I go about doing this. I tried to convert from character to numeric but I got NA results, which I am guessing is to do with the colon.

awz1
  • 419
  • 2
  • 12
  • Try with `library(data.table);as.ITime(time_dataset)` You could add or subtract i.e. `as.ITime(time_dataset) + as.ITime("00:30:00")# [1] "11:10:00" "16:03:00" "02:42:00" "08:31:00" "13:45:00"` – akrun Mar 24 '21 at 16:31
  • Suggested duplicate: [How to handle times without dates in R?](https://stackoverflow.com/q/22659947/903061) – Gregor Thomas Mar 24 '21 at 16:33
  • Some alternatives here: [Convert hour:minute:second (HH:MM:SS) string to proper time class](https://stackoverflow.com/questions/12034424/convert-hourminutesecond-hhmmss-string-to-proper-time-class). Perhaps some adjustments for your (apparent) lack of seconds. – Henrik Mar 24 '21 at 16:33

0 Answers0