[R] Date parsing question

Gabor Grothendieck ggrothendieck at myway.com
Thu May 27 12:50:05 CEST 2004


Ajay Shah <ajayshah <at> mayin.org> writes:

> 
> How do I parse a date "yyyymmdd"? I tried asking chron(s, "ymd") but
> that didn't work. Would the date parsing routines of the Date class of
> 1.9 grok this?
> 


Others have already mentioned z <- as.Date("20040527",format="%Y%m%d")
and if you want it as a chron date try:

chron(unclass(z))

The percent codes in Date are convenient so that's probably the way
to go but just for fun, to do it in chron without using the Date class
you could convert it to the form 05/27/2004 using sub and then apply 
chron:

chron(sub("(....)(..)(..)","\\2/\\3/\\1","20040527"))




More information about the R-help mailing list