Date formats in as.Date

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

Date formats in as.Date

Worik R
I have trouble with this:

as.Date("Sep-1981", format="%b-%Y")

Returns "NA"

>From documentation for strftime

 '%b' Abbreviated month name in the current locale. (Also matches
          full name on input.)

   '%Y' Year with century.

What am I doing wrong?

cheers
Worik

        [[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: Date formats in as.Date

Jim Porzak
Worik,

You need a day!

as in:
as.Date("1-Sep-1981", format="%d-%b-%Y")  ## first of the month

HTH,
Jim Porzak
Ancestry.com
San Francisco, CA
www.linkedin.com/in/jimporzak
use R! Group SF: www.meetup.com/R-Users/


On Thu, Sep 24, 2009 at 4:15 PM, Worik R <[hidden email]> wrote:

> I have trouble with this:
>
> as.Date("Sep-1981", format="%b-%Y")
>
> Returns "NA"
>
> >From documentation for strftime
>
>  '%b' Abbreviated month name in the current locale. (Also matches
>          full name on input.)
>
>   '%Y' Year with century.
>
> What am I doing wrong?
>
> cheers
> Worik
>
>        [[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.
>

        [[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: Date formats in as.Date

Gabor Grothendieck
In reply to this post by Worik R
Try this:

> library(zoo)
> as.yearmon("Sep-1981", "%b-%Y")
[1] "Sep 1981"

> as.Date(as.yearmon("Sep-1981", "%b-%Y"))
[1] "1981-09-01"

> as.Date(paste(1, "Sep-1981"), "%d %b-%Y")
[1] "1981-09-01"


On Thu, Sep 24, 2009 at 7:15 PM, Worik R <[hidden email]> wrote:

> I have trouble with this:
>
> as.Date("Sep-1981", format="%b-%Y")
>
> Returns "NA"
>
> >From documentation for strftime
>
>  '%b' Abbreviated month name in the current locale. (Also matches
>          full name on input.)
>
>   '%Y' Year with century.
>
> What am I doing wrong?
>
> cheers
> Worik
>
>        [[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.
>

______________________________________________
[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.