[R] numeric derivation

David Winsemius dwinsemius at comcast.net
Mon Oct 13 01:46:27 CEST 2008


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?

 > 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.



More information about the R-help mailing list