0

I was surprised to discover yesterday that various summary statistics can be calculated on dates. Googling has found lots on syntax required to calculate summary statistics on dates, but very little on how calculations are done. How are summary statistics (mean, sd etc) calculated on dates?

Example R code:

myDates <- as.Date(paste0(sample(1:28, 100, replace=T), '/', 
                          sample(1:12, 100, replace=T), '/', 
                          2013), 
                   '%d/%m/%Y')

mean(myDates)
median(myDates)
sd(myDates)
var(myDates)
luciano
  • 12,197
  • 30
  • 87
  • 119
  • Are you asking how to compute means and SDs? Or are you wondering about how standard formulas for these statistics can validly be applied to dates? – whuber Mar 15 '13 at 20:22
  • I'm asking how standard formulas for these statistics can validly be applied to dates. – luciano Mar 15 '13 at 21:15
  • I'm going to stay with Excel here, although I would guess R works the same way. A date is an integer reflecting the number of days since a start date, January 1, 1900 (although the missed the lack of leap day that year). March 15, 2013 is 41,348. March 16 will be 41,349. Since these are numbers, the math part is now easy. – zbicyclist Mar 15 '13 at 21:22
  • What if mean is a decimal, eg mean of 41348, 41348, 41347, 41347 is 41347.5 – luciano Mar 15 '13 at 21:35
  • 3
    A "date," by definition, is an amount of time elapsed from a fixed origin, such as Dec 31 1899, January 1 1970, or January 1 CE. As such it is a *numerical quantity*. A fractional date of course is a fractional amount of time; for example, right now it's about 3/4 of the way through the day here (almost 6:00 pm). Where are the difficulties, then, in computing statistics for those numbers? @zbicyclist In Excel a date is a *floating point number* representing days elapsed since the end of the year 1899. This allows Excel to represent times of day as well as days. – whuber Mar 15 '13 at 21:44
  • Dates work the same way in SAS. We routinely looking for median dates, for example. – ReliableResearch Mar 15 '13 at 22:02
  • See: https://stats.stackexchange.com/questions/332688/what-type-of-data-are-dates/332715#332715 – kjetil b halvorsen Jul 12 '18 at 01:35

0 Answers0