Re: [R] Simple regex problem

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Sat, 10 May 2008 13:28:39 -0400

Try this (no gsub required):

as.chron(as.Date(xx, "%b %d, %Y"))

On Sat, May 10, 2008 at 12:49 PM, John Kane <jrkrideau_at_yahoo.ca> wrote:
> I am cleaning up some character data to convert to
> dates using chron. The regex that I am using work fine
> but there should be a better way to do this. Can
> anyone suggest a cleaner bit of code than the gsub,
> sub approach? Thanks
>
> #Test Run on dates.
> xx <- c("May 1, 2007",
> "May 2, 2007",
> "May 3, 2007",
> "May 4, 2007",
> "May 5, 2007",
> "May 6, 2007",
> "May 7, 2007",
> "May 8, 2007",
> "May 9, 2007",
> "May 10, 2007",
> "May 11, 2007",
> "May 12, 2007")
> yy <- gsub(" +", "/", xx) ; yy
> zz <- sub(",", "", yy) ; zz
> library(chron)
> ttdates <- chron(zz, format = c(dates = "mon/d/y"))
>
> ______________________________________________
> 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.
>



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. Received on Sat 10 May 2008 - 17:45:07 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 13 May 2008 - 14:30:38 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive