[R] Extracting months and years from Dates while keeping order

From: Dimitri Liakhovitski <dimitri.liakhovitski_at_gmail.com>
Date: Fri, 06 May 2011 16:07:19 -0400


I'd like to take Dates and extract from them months and years - but so that it sorts correctly. For example:

x1<-seq(as.Date("2009-01-01"), length = 14, by = "month")

order(x1) # produces correct order based on full dates

# Of course, I could do "format" - but this way I am losing the "Date" quality of the data:



Not sure it's possible at all: But is there some other way to extract just months and years from Dates (while ingoring days) - but so that it's still somehow a Date object?

Thank you very much!

Dimitri Liakhovitski
Ninah Consulting

R-help_at_r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Fri 06 May 2011 - 20:09:32 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 06 May 2011 - 20:20:05 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive