[R] finding the year of a date
ggrothendieck at gmail.com
Mon Oct 25 18:46:25 CEST 2010
On Mon, Oct 25, 2010 at 12:38 PM, Dimitri Liakhovitski
<dimitri.liakhovitski at gmail.com> wrote:
> I know that I can use as.yearmon in the package "zoo" to find the year
> and the month of a date.
> I can use as. yearqtr to find the year and the quarter.
> But how can one find just the year of a date?
> Thanks a lot!
Here are three ways. The first uses the fact that the year is the
whole number part of a yearmon object.
> d <- Sys.Date()
> as.numeric(format(d, "%Y"))
> as.POSIXlt(d)$year + 1900
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
email: ggrothendieck at gmail.com
More information about the R-help