Message-ID: <gpnhcv$p2s$1@ger.gmane.org>
Date: 2009-03-17T06:53:20Z
From: Emmanuel Charpentier
Subject: Mean of difftime vectors : "code infelicity" or intended behaviour ?
Dear list,
"+" (and "-") being defined for difftime class, I expected mean() to
return something sensible. This is only half-true :
> mean(c(1:5, 5:1),na.rm=TRUE)
[1] 3
> mean(as.difftime(c(1:5, 5:1),unit="mins"),na.rm=TRUE)
Time difference of 3 mins
Fine so far. However :
> mean(c(1:5, NA,5:1),na.rm=TRUE)
[1] 3
> mean(as.difftime(c(1:5, NA,5:1),unit="mins"),na.rm=TRUE)
Time difference of NA mins
Ouch !
Curiously, var(), max() and min() behave as expected. What's so special
with mean() ?
> RSiteSearch("mean difftime")
[ ... doesn't return anything relevant ]
NB : this isn't done for the hell of it. I intended to replace some
missing dates, with something computed from other dates and mean time
intervals).
Any thoughs ?
Emmanuel Charpentier