Skip to content
Prev 361574 / 398502 Next

Reading and converting time data via read.table

The canonical way to store times is as difftime vectors.  However, there is no simple way to import e.g. HH:MM data directly into such vectors, so you need to embed such times into a longer string that includes a fixed date. After conversion to POSIXct you can subtract the fixed date to get the difftime values.

It is also possible to let the conversion to POSIXct pick "today" by default, but you can sometimes get into trouble if you subtract out "today" on a different day, so I wouldn't recommend it. 

You also may encounter difficulty with daylight savings in this process... but that usually requires knowing a bit more about your data, and if you are already working with time only data you may not be able to fix such problems anyway.