Re: [R] Unexpected behavior for as.date()Hi Terry, Many thanks for your clarifications! It's useful to know where and why things break down and also have a couple of back up options just in case. For now, I'll be extra careful with the date() library; in the future, I'll switch to working with as.Date() and strptime() if possible.
Kind regards, Isabella P.S. Many thanks also to all the contributors to this post who kindly offered alternative solutions to my problem. I really appreciate your time and insights. -----Original Message----- From: Therneau, Terry M., Ph.D. [mailto:thern...@mayo.edu] Sent: November 11, 2009 6:53 AM To: isabe...@ghement.ca Cc: r-help@r-project.org Subject: Re: [R] Unexpected behavior for as.date() The date library was written 20 or so years ago. It was a very good first effort, but the newer Date library has superior functionality in nearly every way. The date library is still available, for legacy projects such as yours, but I do not advise it for new work. To answer your specific questions: 1. What you have is a real bug. The underlying C routine that scans through the text returns "0" as a marker for any string it can't figure out, a year of 'abc' or month 'charlie' for example. The S function then turns these into NA. I never, ever thought about year 0. In our longer term studies at Mayo we have birth dates in the 1800s, it is rather surprising that a birth date of 1900 hadn't caught me sometime in the past. I'll fix this. 2. The date library predates the strptime function by over 10 years. It is not a huge surprise that I neglected to include support for it -- my oracular abilities are limited. For an inherited project such as this I would suggest reading the date() documentation as a first step; it is not very long since the package is simple. You want the date.mdy function, which is more straightforward than strptime (with less capabilities of course). Terry Therneau [[alternative HTML version deleted]] ______________________________________________ R-help@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.