[R] how to cumulate up times
R. Michael Weylandt
michael.weylandt at gmail.com
Tue Apr 24 19:48:44 CEST 2012
Perhaps the easiest way:
library(lubridate)
tms <- as.POSIXct("2007-12-05 09:45:00", format = "%Y-%m-%d %H:%M:%S")
tms + days(3)
Michael
On Tue, Apr 24, 2012 at 12:27 PM, Santosh <santosh2005 at gmail.com> wrote:
> Hello ..
>
> A really simple question for you. for some reason I am not getting it
> right..
>
> How do I add time (in specified units) to a column of observed date/time
> (say a date-time in ISO 8601 format). For example,
> "2007-12-05T09:45:00" + 3 days
> "2007-13-05T09:45:00" + 3 hours
>
>
> Thanks so much!
>
> Santosh
>
> On Tue, Apr 24, 2012 at 9:15 AM, René Mayer <mayer at psychologie.tu-dresden.de
>> wrote:
>
>> Thanks Michael,
>> cumsum - yes of course!
>> Regards,
>> René
>>
>>
>> Zitat von "R. Michael Weylandt" <michael.weylandt at gmail.com>:
>>
>>
>> ? cumsum
>>>
>>> something like
>>>
>>> library(chron) # Reporting packages you use is always considerate
>>> mt <- times(c('00:05:00', '00:15:00', '00:30:00')) # Spaces are legible!
>>>
>>> times("09:30:00") + cumsum(mt)
>>>
>>> Michael
>>>
>>> On Tue, Apr 24, 2012 at 11:35 AM, René Mayer
>>> <mayer at psychologie.tu-dresden.**de <mayer at psychologie.tu-dresden.de>>
>>> wrote:
>>>
>>>> Dear List,
>>>> given a vecor of times in 5,15 and 30 minutes and a start point
>>>> in time, lets say 09:30:00, how do I add up those times
>>>> to the start time getting a cumulative time sequence?
>>>>
>>>> mt<-times(c('00:05:00', '00:15:00', '00:30:00'))
>>>> mt wanted
>>>> 00:05:00 09:35:00
>>>> 00:15:00 09:50:00
>>>> 00:30:00 10:20:00
>>>>
>>>> Regards,
>>>> René
>>>>
>>>> ______________________________**________________
>>>> R-help at r-project.org mailing list
>>>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
>>>> PLEASE do read the posting guide http://www.R-project.org/**
>>>> posting-guide.html <http://www.R-project.org/posting-guide.html>
>>>> and provide commented, minimal, self-contained, reproducible code.
>>>>
>>>
>>>
>> ______________________________**________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
>> PLEASE do read the posting guide http://www.R-project.org/**
>> posting-guide.html <http://www.R-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at 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.
>
More information about the R-help
mailing list