Re: [R] Format ddmmYYYY in date

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Wed, 04 May 2011 07:28:07 -0700

On May 4, 2011, at 5:57 AM, Ben Bolker wrote:

> smoff <simon.frey <at> boku.ac.at> writes:
>
>> My problem is that I have a table containing dates in the first
>> column of 10
>> years. These dates have the format ddmmYYYY at least in the csv-
>> file. After
>> importing the file using read.table() R deletes the first character
>> if it is
>> a zero.
>
> [snip]
>
>> How do I solve this problem? Is there a way to tell R not to delete
>> the
>> first character even if it is a zero or to directly read the first
>> column as
>> date?
>
> See the "colClasses" argument of ?read.table ...
>
> (added a little bit of text to make gmane happy)

I've had similar problems and this was my first strategy:

 > test <- c('1241949', '5182001','12252009')  > ifelse(nchar(test)==7, paste("0", test, sep=""), test) [1] "01241949" "05182001" "12252009"

I then used colClasses, and later simply asked to have all dates in the output format from the database changed to "YYYY-mm-dd".

>
> ______________________________________________
> R-help_at_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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT



R-help_at_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. Received on Thu 05 May 2011 - 06:25:02 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 05 May 2011 - 07:00:05 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive