[R] read.table behavior for Dates.

Kjetil Halvorsen kjetilbrinchmannhalvorsen at gmail.com
Fri Apr 16 21:47:26 CEST 2010


use the argument   colClasses of read.table

Kjetil

On Fri, Apr 16, 2010 at 3:32 PM, Jeroen Ooms <jeroenooms at gmail.com> wrote:
>
> When read.table imports a table that includes a header called 'Date', it
> tries to recognize the date format. For example, if one imports this data
> from Yahoo finance, the Date column is automatically transformed to Y-m-d,
> whereis in the data it appears as m/d/Y:
>
> myData <-
> read.csv("http://ichart.finance.yahoo.com/table.csv?s=GOOG&a=07&b=19&c=2004&d=03&e=16&f=2010&g=d&ignore=.csv")
>
> However, it does not actually convert the variable to Date format.
> MyData$Date is still a factor. This combination of converting the format but
> not attributing the 'Date' class is for me extremely unfortunate behavior.
> My scripts still don't recognize the variable as being a date, but it also
> becomes harder to manually convert it using as.Date() because it is no
> longer in the original format.
>
> Is there a way to either automatically convert to as.Date() when a date
> format has been detected, or otherwise disable this transformation at all?
>
>
> --
> View this message in context: http://n4.nabble.com/read-table-behavior-for-Dates-tp2013442p2013442.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list