What Time Is It?

A common scenario that I run into is time and how to deal with it. I often will do a variety of summaries and analysis that need to be measured at different points in time. Whether I want to graph the data or review the results I need to be able to perform measurements relative to time and interpret the time output in human readable form. R has several functions to handle those time related scenario.

For starters one thing needs to be acknowledged. On Unix based system the beginning of time is January 1, 1970. At that moment exactly zero (0) seconds have passed and it is known as Unix epoch. Anything before that is negative and anything after that time is positive. This measure of time is defined in seconds.

This piece of code shows the Unix epoch and how it compares to the current time. In this example the origin is zero (0) but as one can see it can easily be changed to calculate the length of time that has past since any given time.

##Local Time in EDT (GMT-5). If local time IS GMT then the date would be January 1, 1970
iso <- ISOdatetime(1969,12,31,19,0,0) # (YYYY,MM,DD,HH,MM,SS)
origin <- as.double(iso)
t <- Sys.time()
curr.time <- as.double(t)
curr.time - origin

The following bit of code simulates a cumulative process where each consecutive process follows a Poisson distribution and (lambda) is a random variable distributed uniformly. This would be comparable to a process where election vote counts are being collected throughout Election Night.