[R] read.table behavior for Dates.
David Winsemius
dwinsemius at comcast.net
Sat Apr 17 15:55:39 CEST 2010
On Apr 16, 2010, at 4:42 PM, Jeroen Ooms wrote:
>
> Ah Phil Spector is right, nothing is converted. I'm almost too
> embarrassed to
> admit it, but actually, it was Excel that tricked me. It displays date
> fields differently than they are stored in the csv file, and once
> you press
> 'save', it saves everything to a different format, completely unasked.
>
> Nevertheless I got some valuable insight in the topic. What I'm
> trying to do
> here is make it easier for people to upload files that might contain
> dates
> to my webapp at yeroon.net/ggplot2. Currently, dates are imported as
> factors.
Only if one does not use as.is=TRUE
> I would like to implement something that Henrique described, to
> automatically convert variables to Date that are obviously dates.
If they are in YYYY-MM-DD format then colClasses is the way forward.
If you want to program a recognition strategy when you do not in
advance know the position of the date fields, then use readLines to
get a few lines and parse the fields and use Dallazuanna's regex
search for an "nnnn-nn-nn" pattern (perhaps with a "^|
whitespace<pattern>whitespace|$" wrapper around that pattern to avoid
Social Security fields or similar).
I suspect most experienced useRs would rather not have automatic data
conversion. Your request appears to be emulating a "feature" that is
considered undesirable Excel behavior.
--
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list