printing difftime summary
* David Winsemius <qjvafrzvhf at pbzpnfg.arg> [2012-11-23 13:14:17 -0800]:
--8<---------------cut here---------------start------------->8---
summary.difftime <- function (v) {
s <- summary(as.numeric(v))
r <- as.data.frame(sapply(s,difftime2string),stringsAsFactors=FALSE)
names(r) <- c("string")
r[[units(v)]] <- s
class(r) <- c("data.frame","summary.difftime")
r
}
print.summary.difftime <- function (sd) print.data.frame(sd)
--8<---------------cut here---------------end--------------->8---
it appears to work for a single vector:
--8<---------------cut here---------------start------------->8---
r1 <- summary(infl$delay) r1
string secs Min. 492.00 ms 0.5 1st Qu. 18.08 min 1085.0 Median 1.77 hrs 6370.0 Mean 8.20 hrs 29530.0 3rd Qu. 8.12 hrs 29250.0 Max. 6.98 days 602900.0
str(r1)
Classes 'summary.difftime' and 'data.frame': 6 obs. of 2 variables: $ string: chr "492.00 ms" "18.08 min" "1.77 hrs" "8.20 hrs" ... $ secs :Classes 'summaryDefault', 'table' num [1:6] 4.92e-01 1.08e+03 6.37e+03 2.95e+04 2.92e+04 ... --8<---------------cut here---------------end--------------->8--- but not as a part of data frame: --8<---------------cut here---------------start------------->8---
a <- summary(infl)
Error in summary.difftime(X[[22L]], ...) : unused argument(s) (maxsum = 7, digits = 12) --8<---------------cut here---------------end--------------->8--- I guess I should somehow accept a list of options in summary.difftime() and pass them on to the inner call to summary() (or should it be explicitly summary.numeric()?) how do I do that?
Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://camera.org http://jihadwatch.org http://americancensorship.org http://truepeace.org http://memri.org Why do you never call me back after I scream that I will never talk to you again?!