[R] Parsing unusual date format

Gabor Grothendieck ggrothendieck at gmail.com
Thu Dec 18 11:05:23 CET 2008


Try using the yearmon class in zoo:

> library(zoo)
> d <- c("1990m3", "1992m8")
> ym <- as.yearmon(d, "%Ym%m")
> ym
[1] "Mar 1990" "Aug 1992"
> as.Date(ym)
[1] "1990-03-01" "1992-08-01"


On Thu, Dec 18, 2008 at 1:14 AM, Shruthi Jayaram
<shruthi.jayaram.85 at gmail.com> wrote:
>
> Hello,
>
> If I have a character string like
>
> d <- c("1990m3", "1992m8") #March 1990 and Aug 1992
>
> what is the easiest way to convert it into any standard date form; for
> example,
>
> d <- c("01/03/1990", "01/08/1992")
>
> I looked at as.Date but it doesn't seem to address my problem as I have an
> "m" stuck in the middle of my character string which R does not recognise.
>
> Would be very grateful for any help on this.
>
> Shruthi
> --
> View this message in context: http://www.nabble.com/Parsing-unusual-date-format-tp21067562p21067562.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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