[R]
Simon Wotherspoon
Simon.Wotherspoon at utas.edu.au
Mon Mar 24 05:17:41 CET 2003
Hi,
In 1.6.2 at least, when constructing a sequence of dates with seq and the
by argument inherits from difftime, the "units" attribute seems to be
ignored. E.g.
try
str <- strptime("23/3/2003 06:00:00","%d/%m/%Y %H:%M:%S")
end <- strptime("23/3/2003 06:02:00","%d/%m/%Y %H:%M:%S")
step <- strptime("23/3/2003 06:01:00","%d/%m/%Y %H:%M:%S") -
strptime("23/3/2003 06:00:00","%d/%m/%Y %H:%M:%S")
seq(str,end,step)
A possible fix is to replace the lines
if (inherits(by, "difftime")) {
by <- unclass(by)
}
in seq.POSIXt with
if (inherits(by, "difftime")) {
by <- switch(attr(by, "units"), secs = by, mins = 60 * by, hours = 60 *
60 * by, days = 60 * 60 * 24 * by, weeks = 60 * 60 *
24 * 7 * by)
}
as in "-.POSIXt", but this may not be the best solution.
I can't really see the point of representing difftime objects in terms of
different units, given POSIXct is always stored as seconds. Would it be
better to move the whole "unit" business into a print method, more or less
as it is for POSIXct?
Simon.
---
More information about the R-help
mailing list