[R] extract day or month as in Splus
Karl Ove Hufthammer
karl at huftis.org
Tue Oct 27 09:13:30 CET 2009
On Fri, 23 Oct 2009 12:06:28 -0600 Fang (Betty) Yang
<fang.yang at ualberta.ca> wrote:
> dates <- c("02/27/1992", "02/27/1992", "01/14/1992", "02/28/1992",
> "02/01/1992")
>
> Could anyone give me some R codes to get the same results as above'
> (extract days from dates), please?
If your dates are real dates, and not just character strings, the
simplest way is to use the 'weekdays' functions. For you data:
# Convert the character strings to dates
dates=as.Date(dates, format="%m/%d/%Y")
# Extract the day names (note that these are localised day names)
weekdays(dates)
See the help file for 'weekdays' for details.
--
Karl Ove Hufthammer
More information about the R-help
mailing list