# Calculating mean for Date values using range and counts

#### info_seekeR

##### New Member
Hi,

For the purpose of calculating the average number of days between 2 transactions, I was always
1. subtracting the greater dates from the lesser dates (as in the LEAD functions available in different software and statistical packages)
2. adding the result of step 1
3. dividing the result of step 2 by the count of days from step 1.

Or, as demonstrated using R:

require(dplyr)

Code:
#load data
myDates <- data.frame(dates = as.Date(c('2014-05-10', '2014-08-01', '2012-04-04', '2013-10-02', '2015-01-01', '2015-01-20', '2015-02-25')))
myDates %>% arrange(dates) %>% mutate(subtrDates = lead(dates) - dates) %>% summarise(meanDays = mean(subtrDates, na.rm = TRUE))
#176.1667 days
However, I have noticed a colleague using another method:
1. Find the range of the date values (max - min)
2. divide the range by the count of date values - 1

Code:
#colleague's method
dayDiff <- max(myDates$dates) - min(myDates$dates)
dayDiff/(nrow(myDates) - 1)
#176.1667 days
This was a quick solution, but I hadn't seen previously such a way of calculating the average number of days between events.
I thought about testing this with non-date data

#testing this with non-date data
sampleData <- rnorm(n = 30, mean = 40, sd = 4)
mean(sampleData)
#39.276
(max(sampleData) - min(sampleData))/(length(sampleData))
#0.5000613
So, I think my colleague's method works only for date values, but my questions are:
1. How come it works with date data? Is it because the characteristic of date values that they always increase by a 1, or is there any other statistical property that I am ignorant of?
2. Are there any cases in which my colleague's method will not work even on date data?

Any further comments/thoughts will also be much appreciated.