[R] reading dates

Suchandra Thapa s-thapa-11 at alumni.uchicago.edu
Wed Jan 16 16:26:40 CET 2002


On Wed, Jan 16, 2002 at 06:31:58AM +0000, Prof Brian Ripley wrote:
> There are so many possible formats of dates that any attempt to automate
> this is bound to lead to problems.

    The date is currently in %Y-%m-%d %H:%M format.  
     
> `In principle' because you need to set up as() to do the conversion (and
> that is part of the methods package and not set up out-of-the-box).

    Okay, I'm trying that but seem to be having some difficulties.  
Using this:

setClass('POSIXlt', representation(sec="numeric", 
                                   min="numeric",
                                   hour="numeric",
                                   mday="numeric",
                                   mon="numeric",
                                   year="numeric",
                                   wday="numeric",
                                   yday="numeric",
                                   isdst="numeric"))
setAs('POSIXlt', 'character', function(from) strptime(from, format="%Y-%m-%d %H:%M"))

allows the read.table to work and read the file in however I can't seem
to get individual dates. After running

foo <- read.table(file="output", as.is=c(T, F), colClasses=c('POSIXlt', 'double'), col.names=c('date', 'price'))

foo$date[1] gives all the second fields instead the first date.

> What's the problem with what you are doing now?
    
    Primarily that it doesn't work very well.  Also I'm trying to simplify
things as much as possible so that the person the script is being written 
for can understand it easily.

-- 
------------------------------------------------------------------

Suchandra S. Thapa 
s-thapa-11 at alumni.uchicago.edu

------------------------------------------------------------------
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list