[R] time mathematics

Enrico Schumann e@ @ending from enrico@chum@nn@net
Tue Nov 20 11:23:28 CET 2018


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



More information about the R-help mailing list