[R] printing difftime summary

Sam Steingold sds at gnu.org
Thu Nov 22 05:01:07 CET 2012


Hi,

> * arun <fznegcvax111 at lnubb.pbz> [2012-11-21 14:04:36 -0800]:
>
> Are you looking for some other function (difftime2string)
> ot just remove the quotes from the printed output?

I am wondering what others do when they want to see a summary of difftime.

> If it is the latter, then this should do it.
> res<-do.call(data.frame,lapply(s,difftime2string))
>  names(res)<-names(s)
>  res
> #       Min.   1st Qu.    Median     Mean  3rd Qu.      Max.
> #1 500.00 ms 17.12 min 99.48 min 8.30 hrs 8.05 hrs 6.98 days

cool, thanks.
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
}
> difftime.summary(infl$delay)
           string     secs
Min.    500.00 ms      0.5
1st Qu. 17.12 min   1027.0
Median  99.48 min   5969.0
Mean     8.30 hrs  29870.0
3rd Qu.  8.05 hrs  28970.0
Max.    6.98 days 603100.0
--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://ffii.org http://jihadwatch.org http://memri.org
http://www.memritv.org http://camera.org http://mideasttruth.com
A computer scientist is someone who fixes things that aren't broken.




More information about the R-help mailing list