[R] HMisc describe -- error with dates

Tanya Murphy tmurph6 at po-box.mcgill.ca
Wed Dec 3 17:53:44 CET 2003


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?


Tanya




More information about the R-help mailing list