[R] day, month, year functions

Gregor Gorjanc gregor.gorjanc at bfro.uni-lj.si
Fri Aug 11 02:27:27 CEST 2006


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



More information about the R-help mailing list