[R] Convert Character to Date

Gabor Grothendieck ggrothendieck at gmail.com
Tue Mar 31 09:36:03 CEST 2009


The yearmon class in the zoo package can represent year/months:

> library(zoo)
> ym <- as.yearmon("1990-January", "%Y-%B"); ym
[1] "Jan 1990"
> as.Date(ym)
[1] "1990-01-01"


On Tue, Mar 31, 2009 at 3:14 AM, Bob Roberts <quagmire54321 at yahoo.com> wrote:
> Hello,
>   I have a date in the format Year-Month Name (e.g. 1990-January) and R classes it as a character. I want to convert this character into a date format, but when I try as.Date(1990-January, "%Y-%B"), I get back NA. The function strptime also gives me NA back. Thanks.
>
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org 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.
>




More information about the R-help mailing list