[R] Controlling the dates in R;

Gabor Grothendieck ggrothendieck at gmail.com
Wed Aug 18 15:49:48 CEST 2010


On Wed, Aug 18, 2010 at 3:33 AM, Mangalani Peter Makananisa
<pmakananisa at sars.gov.za> wrote:
> Dear R gurus,
>
>
>
> I am currently using the chron package for date manipulation in R and I
> am able to control  the date which take the format
>
>
>
> -          1998/07/03, and
>
> -          2006-09-15 (date without time)
>
>
>
> Library(chron)
>
> As.Date(2006-09-15, format = '%Y-%m-%d')
>
>
>
> However I  have a problem with the date containing only the year and
> month (i.e. 2006-09, 2007/08, 200609).
>
>
>

zoo has a yearmon class for representing year and month without a date:

library(chron)
library(zoo)

as.chron(as.yearmon("2006-09"))
as.Date(as.yearmon("2006-09"))

or you may be able to just use the yearmon class directly: as.yearmon("2006-09")

See help(yearmon) in zoo.



More information about the R-help mailing list