Re: [R] timediff

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Tue 20 Jun 2006 - 20:56:07 EST

"COMTE Guillaume" <g.comte@alliance-ir.net> writes:

> I've got 2 dates like these :
> "2006-02-08 17:12:55"
> "2006-02-08 17:15:26"
> I wish to get the middle of these two date :
> "2006-02-08 17 :14 :10"
> Is there is a function in R to do that ?

Well,

> x1 <- as.POSIXct("2006-02-08 17:12:55")
> x2 <- as.POSIXct("2006-02-08 17:15:26")
> x2-x1

Time difference of 2.516667 mins
> (x2-x1)/2

Time difference of 1.258333 mins
> x1+60*as.numeric((x2-x1)/2)

[1] "2006-02-08 17:14:10 CET" However, this goes wrong (although not without warning):
> x1+(x2-x1)/2
[1] "2006-02-08 17:12:56 CET"
Warning message:
Incompatible methods ("+.POSIXt", "Ops.difftime") for "+"

---for reasons that are related to this:
> as.numeric(x2)-as.numeric(x1) # seconds!
[1] 151
> as.numeric(x2-x1) # minutes

[1] 2.516667

(This suggests to me that the methodology for difftime objects is still not quite complete. Volunteers?)

-- 
   O__  ---- Peter Dalgaard             ุster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Tue Jun 20 21:01:49 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 21 Jun 2006 - 08:13:45 EST.

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