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
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
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL:
<https://stat.ethz.ch/pipermail/r-help/attachments/20181120/197b5959/attachment-0001.sig>