[R] how to shift a chron timestamp by 6:30 hours

David Winsemius dwinsemius at comcast.net
Thu Jul 28 16:31:31 CEST 2011


On Jul 28, 2011, at 9:37 AM, Maciej Hoffman-Wecker wrote:

> Dear help list,
>
> I have a timestamp in as a chron object:
>
It would have been courteous to put in:

library(chron)
>> (x <- chron(dates = c("12/02/11", "22/11/11"),
> +             times = c("07:30:00", "04:00:00"),
> +             format = c(dates = "d/m/y", times = "h:m:s")))
> [1] (12/02/11 07:30:00) (22/11/11 04:00:00)
>
> Now I want to shift the timestamp by 06:30 (hh:mm) backwards, to get
>
> [1] (12/02/11 01:30:00) (21/11/11 21:30:00)

(Your time subtraction is a bit different than R's ... or mine)

 > x - 6.5/24
[1] (12/02/11 01:00:00) (21/11/11 21:30:00)

chron times are represented as days, so 6 1/2 hours is 6.5/24

>
> How can I achieve this? Are there any more detailed examples on
> manipulation of chron objects? I have some trouble with this.

The help page has quite a few examples. I didn't know the answer but  
after reading the help page it was pretty easy to figure out.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list