Re: [R] day, month, year functions

From: Gregor Gorjanc <gregor.gorjanc_at_bfro.uni-lj.si>
Date: Fri 11 Aug 2006 - 10:27:27 EST

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

Hi,

it would really be great if there would be

sec(), min(), hour() day(), month(), year()

generic functions that would work on all "date" classes. Where applicable of course. I imagine that argument to get out integer or character would alse be nice.

Gregor



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri Aug 11 11:39:50 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 17 Aug 2006 - 20:21:36 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.