[R] numeric derivation

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Oct 13 08:53:32 CEST 2008


On Sun, 12 Oct 2008, David Winsemius wrote:

> Two follow-up questions:
>
> A) I get an error message when using Harrell's describe() function on one of 
> my variable,  telling me that sum() is not meaningful for a difftime object. 
> Why should sum() not be meaningful for a collection of interval lengths?

That's not what it actually says.  It says it is 'not defined' -- it could 
be defined but it has not been.  Just add a function sum.difftime() with 
appropriate code (and watch out that different difftime objects can be in 
different units).

>> describe(pref900)
> Error in Summary.difftime(c(1075, 3429, 2915, 2002, 967, 1759, 532, 589,  :
> 'sum' not defined for "difftime" objects
>
> summary() is informative and throws no error, but does not report means. 
> Even with na.rm=TRUE,  sum fails:
>> sum(pref900$deatht, na.rm=TRUE)
> Error in Summary.difftime(c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,  :
> 'sum' not defined for "difftime" objects
>
> My interest in the sum of difftime objects comes from my interest in 
> calculating the number of person-years of observation in various categories. 
> I have durations created by subtracting times.
>
>
> B) The help pages are not particularly expansive regarding the output of 
> deltat() but your answer suggests that it should work on non-time objects as 
> well? Am I correct in assuming you meant that diff(x)/deltat(x) should be 
> meaningful for any numeric x.
>
> -- 
> David Winsemius
> R 2.7.1 / Mac OS 10.5.4 / Intel CPUs
>
> s>
> On Oct 12, 2008, at 10:34 AM, Gabor Grothendieck wrote:
>
>> ?deltat
>> 
>> On Sun, Oct 12, 2008 at 9:45 AM, Oliver Bandel
>> <oliver at first.in-berlin.de> wrote:
>>> Zitat von Gabor Grothendieck <ggrothendieck at gmail.com>:
>>> 
>>>> If you simply want successive differences use diff:
>>>> 
>>>> x <- seq(4)^2
>>>> diff(x)
>>>> 
>>>> tx <- ts(x)
>>>> diff(tx)
>>> [...]
>>> 
>>> Oh, cool, thanks.
>>> 
>>> But what about  diff / delta_t ?
>>> 
>>> Do I have to calculate it by my own, or is there
>>> already a function for making a difference-qoutient?
>>> 
>>> This would be fine to have, because for example
>>> coming from space vs. time to velocity vs. time
>>> and acceleration vs. time (and further derivatives)
>>> are also a time-series.
>>> 
>>> The possibility of using the advantages of the time series class here,
>>> would be fine.
>>> 
>>> 
>>> Ciao,
>>> Oliver
>>> 
>> 
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide 
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list