Skip to content
Prev 311829 / 398503 Next

printing difftime summary

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