[R] Accessing date subfields

Maciej Radziejewski maciejr_copies at yahoo.com
Tue Jun 20 14:20:38 CEST 2006


Hello,

I can't figure out a "proper" way to extract the month number from a Date class variable. I can do it like this:

> today <- as.Date(Sys.time())
> as.integer (format.Date (today, "%m"))

but it must be inefficient, since I convert a date to text and back to a number. I tried:

 > months(today)

but the months() function returns the name of the month, not the month number. I need to process some time series of station data using  season-dependent criteria, so I need the months numerically.

Thanks in advance for any help,

Maciej.



More information about the R-help mailing list