I have a series of timestamps (expressed as Unix time) representing certain dates when an event happened. I want to analyze these timestamps to find information such as:

  1. average time between events
  2. find out if the timestamps are evenly distributed or tend to group in periodic clumps
  3. if the timestamps do indeed group around periodic clumps, find the center of these clumps.

Can you please tell me how I can compute these? Is there an R package for descriptive statistics for dates (or other statistical software out there)?

For issue 1. I can just write a for loop to compute the average time between events, but issue 2. and 3. are more tricky.


As @Peter Ellis has pointed out, getting differences between dates is a matter of some difference function or an easy subtraction, depending on your software.

For a small number of dates, clusters should be evident in any univariate distribution display.

For a larger number of dates, plotting (cumulative) number of events so far can identify cluster centres. If the pattern is like random dates from a uniform distribution, expect a line of constant slope with trivial fluctuations. If there are clusters, expect a staircase or stepped effect. (This graph can also show shifts in average frequency.)

Periodicities are alluded to here. Plotting occurrences against time of day, week, month, year or whatever is germane may help too.

All that said, the tougher questions have an answer here:

How can I group numerical data into naturally forming "brackets"? (e.g. income)

but I haven't searched for an R implementation. The code for the Stata implementation mentioned there is in the public domain and mostly written in Mata, a C-like language within Stata with strong support for matrices.

Note I've seen people confused by this, so I will add what is evident on a little thought. With dates, treated numerically as time lapsed since some origin, mean, minimum, maximum, median, etc. also have an interpretation as dates or as positions on a date line. Standard deviation, IQR, range are durations or elapsed times, not dates. With these simple caveats, ordinary functions, commands or routines for descriptive statistics are useful for dates, treated (if necessary, converted or coerced) as numeric variables. Even if you are smart on this, your software may be a little dumb.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.