printing difftime summary
* David Winsemius <qjvafrzvhf at pbzpnfg.arg> [2012-11-26 08:46:35 -0800]: On Nov 26, 2012, at 7:14 AM, Sam Steingold wrote:
summary(infl), where infl$delay is a difftime vector, prints
...
delay
string:c("492.00 ms", "18.08 min", "1.77 hrs", "8.20 hrs", "8.13 hrs",
"6.98 days")
secs :c(" 0.5", " 1085.1", " 6370.2", " 29534.4", " 29254.0",
"602949.7")
instead of something like
delay
Min.: 492 ms
1st Qu.: 18.08 min
&c
so, how do I arrange for a proper printing of difftime summary as a
part
of the data frame summary?
If you like a particular format from an existing print method then why not look it up and copy the code? methods(print)
the problem is that I cannot figure out which function prints this:
delay
string:c("492.00 ms", "18.08 min", "1.77 hrs", "8.20 hrs", "8.13 hrs",
"6.98 days")
secs :c(" 0.5", " 1085.1", " 6370.2", " 29534.4", " 29254.0",
"602949.7")
I added cat()s to print.summary.difftime and I do not see them, so it
appears that I have no direct control over how a summary.difftime is
printed as a part of a summary of a data.frame.
--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("summary.difftime","data.frame")
invisible(r)
}
print.summary.difftime <- function (sd, ...) {
cat("[[[print.summary.difftime]]]\n")
print(list(...))
print.data.frame(sd, ...)
}
--8<---------------cut here---------------end--------------->8---
Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://palestinefacts.org http://think-israel.org http://www.memritv.org http://openvotingconsortium.org http://mideasttruth.com The force of gravity doubles when acting on a body on a couch.