time mathematics

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

time mathematics

Knut Krueger-8

I have an dataframe from with a given time format:

"23:01:19"

to change some given data:

x=data.frame
("Y"=c(1:5),"TIME"=c("23:01:18","23:01:18","23:01:18","23:01:18","23:01:18"))

I need to change  the time increasing in seconds

x=data.frame
("Y"=c(1:5),"TIME"=c("23:01:18","23:01:19","23:01:20","23:01:21","23:01:22"))


Is it possible without any additional package ?


Kind Regards Knut

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: time mathematics

Enrico Schumann-2
On Tue, 20 Nov 2018, Knut Krueger writes:

> I have an dataframe from with a given time format:
>
> "23:01:19"
>
> to change some given data:
>
> x=data.frame
> ("Y"=c(1:5),"TIME"=c("23:01:18","23:01:18","23:01:18","23:01:18","23:01:18"))
>
> I need to change  the time increasing in seconds
>
> x=data.frame
> ("Y"=c(1:5),"TIME"=c("23:01:18","23:01:19","23:01:20","23:01:21","23:01:22"))
>
>
> Is it possible without any additional package ?
>
>
> Kind Regards Knut
>

Like so?

    start <- "23:01:18"
    Y <- 1:5
    tmp <- as.POSIXct(paste(Sys.Date(), start))
    tmp <- tmp + seq(from = 0, length.out = length(Y))
    format(tmp, "%H:%M:%S")
    ## [1] "23:01:18" "23:01:19" "23:01:20" "23:01:21" "23:01:22"

    data.frame(Y, TIME = format(tmp, "%H:%M:%S"))



--
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: time mathematics

Bjørn-Helge Mevik-3
In reply to this post by Knut Krueger-8
Well, this is not an elegant (or robust) solution, but this would work
for the example you give, at least:

starttime <- as.POSIXct("2018-11-20 23:01:18") # Just pick a random date
format(starttime + c(0:4), format = "%T")

There are probably better ways. :)

--
Regards,
Bjørn-Helge Mevik

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.

signature.asc (847 bytes) Download Attachment