Maciej Hoffman-Wecker
2011-Jul-28 13:37 UTC
[R] how to shift a chron timestamp by 6:30 hours
Dear help list, I have a timestamp in as a chron object:> (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) How can I achieve this? Are there any more detailed examples on manipulation of chron objects? I have some trouble with this. Thanks in advance, Maciej Hoffman-Wecker
Create a difftime object and subtract it from your chron vector. --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil@dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. Maciej Hoffman-Wecker <Maciej.Hoffman-Wecker@bioskin.de> wrote: Dear help list, I have a timestamp in as a chron object:> (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) How can I achieve this? Are there any more detailed examples on manipulation of chron objects? I have some trouble with this. Thanks in advance, Maciej Hoffman-Wecker _____________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]]
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
On Thu, Jul 28, 2011 at 9:37 AM, Maciej Hoffman-Wecker <Maciej.Hoffman-Wecker at bioskin.de> wrote:> Dear help list, > > I have a timestamp in as a chron object: > >> (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) >Try this: x - as.numeric(times("06:30:00")) If you actually wanted 6 hours behind, which is what the desired result shown in the post implies, then use "06:00:00" instead. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
Maybe Matching Threads
- Import of Access data via RODBC changes column name ("NO" to "Expr1014") and the content of the column
- methods on missing data
- hours() in 'chron': output != input
- make error R-1.8.0 on SuSE Linux 7.3 (i386)
- having trouble extracting week from chron object