From p.dalgaard at biostat.ku.dk  Tue Sep  7 00:54:41 2004
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: Tue Sep  7 00:55:04 2004
Subject: [Rd] Glitch involving difftime and data frame
In-Reply-To: <Pine.LNX.4.44.0409062326140.27999-100000@gannet.stats>
References: <Pine.LNX.4.44.0409062326140.27999-100000@gannet.stats>
Message-ID: <x2hdqb2eku.fsf@biostat.ku.dk>

Prof Brian Ripley <ripley@stats.ox.ac.uk> writes:

> On 7 Sep 2004, Peter Dalgaard wrote:
> 
> > This looks unintentional:
> 
> Not so.
> 
> > > d <- as.Date("2004-09-07")
> > > dd <- as.Date("2004-10-04")
> > > data.frame(d,dd,dd-d)
> > Error in as.data.frame.default(x[[i]], optional = TRUE) :
> >         can't coerce difftime into a data.frame
> > > F <- data.frame(d,dd)
> > > F$foo <- dd-d
> > > cbind(F,dd-d)
> > Error in as.data.frame.default(x[[i]], optional = TRUE) :
> >         can't coerce difftime into a data.frame
> > 
> > Basically, the issue is that as.data.frame on a classed object expects
> > to find a method and there isn't any for difftime...
> 
> Difftime depends crucially on attributes on the vector.  I wasn't 
> confident that they would be preserved as needed (and I think I had a 
> problem example).  Since then we have fixed a lot of the subsetting 
> methods, but even so I am not 100% confident.

Hmm. So to get a survival time (say) into a data frame, we should
unclass it? (That $<- works seems coincidental and the resulting data
frame might cause trouble down the line). It does look rather tempting
to do as.data.frame.difftime <- as.data.frame.numeric and begone with
it though....

(It doesn't make much sense to have units other than "days" for Date
differences, so the use of difftime objects is a bit pointless from
the practical perspective, although perhaps not from a consistency
perspective. Any chance of doing months and years?)

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907


[Rd] Glitch involving difftime and data frame
Peter Dalgaard