[R] printing difftime summary

Sam Steingold sds at gnu.org
Thu Nov 22 18:49:20 CET 2012


> * R. Michael Weylandt <zvpunry.jrlynaqg at tznvy.pbz> [2012-11-22 12:11:55 +0000]:
>
>> I now think that what I want is
>> --8<---------------cut here---------------start------------->8---
>> difftime.summary <- function (v) {
>>   s <- summary(as.numeric(v))
>>   r <- as.data.frame(sapply(s,difftime2string),stringsAsFactors=FALSE)
>>   names(r) <- c("string")
>>   r[[units(v)]] <- s
>>   r
>> }
>
> Any reason not summary.difftime to get S3 dispatch?

I hoped that someone will ask this :-)

1. because its argument has type "vector of difftime", not "difftime"
(coming from CLOS, I do not expect summary(vector of difftime) to
dispatch to summary.difftime, but to summary.vector.of.difftime or something)

2. because difftime.summary returns a data.frame and not a
"Classes 'summaryDefault', 'table'" as I assume summary must return.

if these are not valid issues, then I wonder why my function should not
be the system default method.

-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000
http://www.childpsy.net/ http://memri.org http://honestreporting.com
http://jihadwatch.org http://openvotingconsortium.org http://ffii.org
Sex is like air.  It's only a big deal if you can't get any.




More information about the R-help mailing list