[R] Simple regex problem
John Kane
jrkrideau at yahoo.ca
Sat May 10 18:49:20 CEST 2008
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"))
More information about the R-help
mailing list