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? -- Ajay Shah Consultant ajayshah at mayin.org Department of Economic Affairs http://www.mayin.org/ajayshah Ministry of Finance, New Delhi
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?Yes, trivially:> as.Date("20040527",format="%Y%m%d")[1] "2004-05-27" -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
r-help-bounces at stat.math.ethz.ch wrote on 27/05/2004 11:29:11:> 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?> a <- "20030527" > as.Date(a, "%Y%m%d")[1] "2003-05-27" HTH, Tobias> > -- > Ajay Shah Consultant > ajayshah at mayin.org Department of Economic Affairs > http://www.mayin.org/ajayshah Ministry of Finance, New Delhi > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide!http://www.R-project.org/posting-guide.html
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"))