Controlling the dates in R;

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Controlling the dates in R;

Mangalani Peter Makananisa
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).

 

Please help me with the code(s) to resolve this problem.

 

Kind regards

 

Peter

 

Tel: 012 422 7357

Cell: 082 456 4669

 

 

 


Please Note: This email and its contents are subject to our email legal notice which can be viewed at http://www.sars.gov.za/Email_Disclaimer.pdf 

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Controlling the dates in R;

Gabor Grothendieck
On Wed, Aug 18, 2010 at 3:33 AM, Mangalani Peter Makananisa
<[hidden email]> 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.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.