s-news
[Top] [All Lists]

Re: Time differences calculations

To: <vincent.duval@boehringer-ingelheim.com>, <s-news@lists.biostat.wustl.edu>
Subject: Re: Time differences calculations
From: "Michael Camilleri" <MichaelCamilleri@branz.co.nz>
Date: Thu, 21 Jun 2007 09:29:38 +1200
In-reply-to: <033BC9FB402D2B4CBBBE829F25FEDBE90123C717@bibexm02.eu.boehringer.com>
References: <033BC9FB402D2B4CBBBE829F25FEDBE90123C717@bibexm02.eu.boehringer.com>
Thread-index: AcezFXokPdxHl8pnQmmUHimelwvUXQAaggwg
Thread-topic: Time differences calculations

When you are using time data you should use one of the S+ time and date formats. You can use the old chron() and related functions to create julian dates. You can use the ts and rts times series objects. You can also use the newer TimeSeries objects.

 

The easiest thing to do would be to convert your dates to a numeric value using the chron functions (you may have to load the library using library(chron))

 

20080620.00

 

julian(as.numeric(substring(“20080620.00”,5,6)),as.numeric(substring(“20080620.00”,7,8)),as.numeric(substring(“20080620.00”,1,4))

 

If you have a regular time series you could use the rts function, although a rts object is quite different from a data frame.

 

The timeDate function can also do it, although it is more complex than just reformatting your dates, and has time zones and other stuff buried in it which has the potential to foul things up. You may be able to get the in.format working on your string directly, but it may not work with the format you have choosen.

 

timeDate(charvec, in.format=<<see below>>, format=<<see below>>, zone=<<see below>>, 

         julian, ms, in.origin=c(month=1, day=1, year=1960))

 

 

In short, S+ handles dates most easily as a numeric value, a ts object, or a timeDate object. Which you find easiest is up to you. I have found the numeric respresentation of chron the easiest to work with overall.

Michael

<Prev in Thread] Current Thread [Next in Thread>