[R] HMisc describe -- error with dates

Frank E Harrell Jr feh3k at spamcop.net
Wed Dec 3 18:59:23 CET 2003


On Wed, 3 Dec 2003 11:53:44 -0500
Tanya Murphy <tmurph6 at po-box.mcgill.ca> wrote:

> Thank you Frank and Gabor for the fixes and checking and rechecking! 
> Everything seems to work well with the Hmisc functions tried--upData,
> describe and summary.
> 
> To summarize:
> 1. Add the testDateTime and formatDateTime functions (copied from
> Frank's messages) to the Hmisc file (or run prior to loading Hmisc)
> 
> 
> testDateTime <- function(x, what=c('either','both','timeVaries')) {
>   what <- match.arg(what)
>   cl <- class(x) # was oldClass 22jun03
>   if(!length(cl)) return(FALSE)
> 
>   dc <- if(.R.) c('POSIXt','POSIXct','dates','times','chron') else
>   c('timeDate','date','dates','times','chron')
>   dtc <- if(.R.) c('POSIXt','POSIXct','chron') else
>   c('timeDate','chron')
>   switch(what,
>   either = any(cl %in% dc),
>   both = any(cl %in% dtc),
>   timeVaries = {
>   if('chron' %in% cl || !.R.) { ## chron or S+ timeDate
>   y <- as.numeric(x)
>   length(unique(round(y - floor(y),13))) > 1
>   } else if(.R.) length(unique(format(x,'%H%M%S'))) > 1 else
>   FALSE
>   })
>   }
> 
> formatDateTime <- function(x, at, roundDay=FALSE) {
> cl <- at$class
> w <- if(any(cl %in% c('chron','dates','times'))) {
> attributes(x) <- at
> fmt <- at$format
> if(roundDay) {
> if(length(fmt)==2 && is.character(fmt))
> format.dates(x, fmt[1]) else format.dates(x)
> } else x
> } else if(.R.) {
> attributes(x) <- at
> if(roundDay) as.POSIXct(round(x, 'days')) else x
> } else timeDate(julian=if(roundDay)round(x) else x)
> format(w)
> }
> 
> 2. Replace the decribe function with the new one (available as an
> attachment in Frank's most recent message on the subject). Instead of
> editing the original Hmisc file, this could be run after the Hmisc
> library is loaded.
> 
> Right?

Right, or if you use Linux I can send you a new .tar.gz file with an
update to Hmisc.  Once you do update Hmisc you can drop all the above.

Frank

> 
> 
> Tanya
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help


---
Frank E Harrell Jr    Professor and Chair            School of Medicine
                      Department of Biostatistics    Vanderbilt University




More information about the R-help mailing list