I have multiple lists of measurements. In each list have the timestramp formated as a string ("2009-12-24 21:00:07.0") and I know that each measurement in the list is separated by 5 seconds. I want to combine all data into a huge data.frame in R. Afterwards I want to be able to easily access the time difference of two measurements so I probably should convert data into something different than characters.
Which format should I use to store the times? Is there some time format in some package that I should use?
You want the (standard)
POSIXt
type from base R that can be had in 'compact form' as aPOSIXct
(which is essentially a double representing fractional seconds since the epoch) or as long form inPOSIXlt
(which contains sub-elements). The cool thing is that arithmetic etc are defined on this -- seehelp(DateTimeClasses)
Quick example:
As for reading them in, see
help(strptime)
As for difference, easy too:
Lastly, the zoo package is an extremely versatile and well-documented container for matrix with associated date/time indices.