[R] Accessing date subfields

Petr Pikal petr.pikal at precheza.cz
Tue Jun 20 15:03:10 CEST 2006


Hi

you can also do

as.POSIXlt(today)$mon

but I do not know if it is more efficient

HTH
Petr



On 20 Jun 2006 at 5:20, Maciej Radziejewski wrote:

Date sent:      	Tue, 20 Jun 2006 05:20:38 -0700 (PDT)
From:           	Maciej Radziejewski <maciejr_copies at yahoo.com>
To:             	r-help at stat.math.ethz.ch
Subject:        	[R] Accessing date subfields
Send reply to:  	Maciej Radziejewski <maciejr_copies at yahoo.com>
	<mailto:r-help-request at stat.math.ethz.ch?subject=unsubscribe>
	<mailto:r-help-request at stat.math.ethz.ch?subject=subscribe>

> 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.
> 
> ______________________________________________
> R-help at 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

Petr Pikal
petr.pikal at precheza.cz



More information about the R-help mailing list