[R] Help with adding minutes to time
Gabor Grothendieck
ggrothendieck at gmail.com
Tue May 30 21:01:35 CEST 2006
Try this:
> hhmm <- function(x) sub(":..$", "", format(times(x)))
> y <- times("01:02:00", out.format = hhmm) + times("00:01:00")
> y # or format(y)
[1] 01:03
or
> # hhmm is from above
> x <- times("01:02:00")
> hhmm(x + times("00:01:00"))
[1] "01:03"
On 5/30/06, Jean-Louis Abitbol <abitbol at sent.com> wrote:
> Dear R Helpers,
>
> I need to read time from a .csv file which is formated as chartime
> (09:12:00) below. I need to add one minute (cf chartime2).
> Then I need to output the value just as 09:13 without the seconds for
> writing a csv file and input in another program.
>
> I get it with the following reproducible example but I can't help
> thinking that there must a less clumsy way to do that !
>
> Thanks for any input and eventually a pointer to an example of how to
> add minutes or seconds to a time without a date which I think makes
> POSIX not relevant in this case.
>
> Best regards, Jean-louis
>
>
> library(chron)
> chartime<-"09:12:00"
> chartime2<-"00:01:00"
> chrontime<-times(chartime)
> chrontime2<-times(chartime2)
> test<-chrontime+chrontime2
> test<-as.character(test)
> test<-sub(":00","",test)
>
> ______________________________________________
> R-help at 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
>
More information about the R-help
mailing list