[R] day, month, year functions
Gregor Gorjanc
gregor.gorjanc at bfro.uni-lj.si
Thu Aug 17 10:35:09 CEST 2006
Martin Maechler wrote:
>>>>>> "Gregor" == Gregor Gorjanc <gregor.gorjanc at bfro.uni-lj.si>
>>>>>> on Fri, 11 Aug 2006 00:27:27 +0000 (UTC) writes:
>
> Gregor> Gabor Grothendieck <ggrothendieck <at> gmail.com> writes:
> >>
> >> Here are three ways:
> >>
> >> xx <- as.Date("2006-01-05")
> >>
> >> # 1. use as.POSIXlt
> >> as.POSIXlt(xx)$mday
> >> as.POSIXlt(xx)$mon + 1
> >> as.POSIXlt(xx)$year + 1900
> >>
> >> # 2. use format
> >> as.numeric(format(xx, "%d"))
> >> as.numeric(format(xx, "%m"))
> >> as.numeric(format(xx, "%Y"))
> >>
> >> # 3. use month.day.year in chron package
> >> library(chron)
> >> month.day.year(unclass(xx))$day
> >> month.day.year(unclass(xx))$month
> >> month.day.year(unclass(xx))$year
>
> Gregor> Hi,
>
> Gregor> it would really be great if there would be
>
> Gregor> sec(), min(), hour() day(), month(), year()
>
> Gregor> generic functions that would work on all "date" classes. Where
> Gregor> applicable of course. I imagine that argument to get out integer
> Gregor> or character would alse be nice.
>
> I disagree pretty strongly:
>
> - We definitely don't want min() to return minutes instead of
> minimum !
>
Pheu, a good catch. You are definitely right!
> - Why pollute the namespace with 6 (well, actualy 5!) new
> function names, when as.POSIXlt()
> *REALLY* is there exactly for this purpose ???
>
> I rather think the authors of each of the other old-fashioned
> "date" classes should provide as.POSIXlt() methods for their
> classes.
>
> Then, we'd have uniform interfaces, following's Gabor's "# 1."
> above.
My proposal above was just a "direction" to a common way of dealing with
dates within R. If as.POSIXlt() methods is the way, that is perfectly
fine with me.
--
Lep pozdrav / With regards,
Gregor Gorjanc
----------------------------------------------------------------------
University of Ljubljana PhD student
Biotechnical Faculty
Zootechnical Department URI: http://www.bfro.uni-lj.si/MR/ggorjan
Groblje 3 mail: gregor.gorjanc <at> bfro.uni-lj.si
SI-1230 Domzale tel: +386 (0)1 72 17 861
Slovenia, Europe fax: +386 (0)1 72 17 888
----------------------------------------------------------------------
"One must learn by doing the thing; for though you think you know it,
you have no certainty until you try." Sophocles ~ 450 B.C.
More information about the R-help
mailing list