I have dates in Numeric mode like this: 20/05/2012
What's the most elegant way to extract the year and month from this?
I have dates in Numeric mode like this: 20/05/2012
What's the most elegant way to extract the year and month from this?
First you need to convert it to a date object:
x <- as.Date("20/05/2012", format="%d/%m/%Y")
Then to get the month number:
format(x,"%m")
And to get the year number:
format(x,"%Y")
If you want the month name (note, this is in your machine language):
months(x)