[R] how to work with Year-Month dates

Joshua Wiley jwiley.psych at gmail.com
Fri Sep 17 21:23:17 CEST 2010


Hi all,

Is there a built in or easier way to work with dates that are *just* Year-Month?
Right now I paste() on a day as a work around, but it ultimately needs to be
in Year-Month form, so then I use format() to get rid of the day.

x <- c("2006-December", "2006-July")
x <- paste(x, "-01", sep='')
x <- as.Date(x, "%Y-%B-%d")
x <- sort(x)
x <- format(x, format = "%Y-%B")
> x
[1] "2006-July"     "2006-December"

Thanks,

Josh


-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/



More information about the R-help mailing list