r - How to convert decimal time to time format -
this question has answer here:
- outputting difftime hh:mm:ss:mm in r 1 answer
i calculate difference between 2 time-sets. can this, difference in decimals , know how convert them format in "minutes:second".
so, have minutes , seconds characters:
video_begin <- c("8:14", "4:47", "8:27", "4:59", "4:57", "7:51", "6:11", "5:30") video_end <- c("39:08", "47:10", "49:51", "44:31", "39:41", "47:12", "40:13", "46:52")
i convert them time values as.posixct, make df , add difference third column, easy peasy...
video_begin <- as.posixct(video_begin, format = "%m:%s") video_end <- as.posixct(video_end, format = "%m:%s") video <- data.frame(video_begin, video_end) video$video_duration <- video_end - video_begin
and video
:
video_begin video_end video_duration 1 2017-09-12 00:08:14 2017-09-12 00:39:08 30.90000 mins 2 2017-09-12 00:04:47 2017-09-12 00:47:10 42.38333 mins 3 2017-09-12 00:08:27 2017-09-12 00:49:51 41.40000 mins 4 2017-09-12 00:04:59 2017-09-12 00:44:31 39.53333 mins 5 2017-09-12 00:04:57 2017-09-12 00:39:41 34.73333 mins 6 2017-09-12 00:07:51 2017-09-12 00:47:12 39.35000 mins 7 2017-09-12 00:06:11 2017-09-12 00:40:13 34.03333 mins 8 2017-09-12 00:05:30 2017-09-12 00:46:52 41.36667 mins
how change format of video$video_duration
decimal same format in video$video_begin
, video$video_end
: "minutes:seconds" (i don't care day, month, year , hour)?
i tried:
video$video_duration <- as.posixct(video$video_duration, format = "%m:%s")
and
strptime(video$video_duration, format="%m:%s")
but nah...
i found answers i'm not satisfied them:
how convert decimal posix time
algorithm convert text time decimal time
isn't there more... handy , easier way it?
thanks!
another option:
library(lubridate) video$video_duration <- as.numeric(video_end - video_begin, units = "secs") video$video_duration <- seconds_to_period(video$video_duration) video_begin video_end video_duration 1 2017-09-12 00:08:14 2017-09-12 00:39:08 30m 54s 2 2017-09-12 00:04:47 2017-09-12 00:47:10 42m 23s 3 2017-09-12 00:08:27 2017-09-12 00:49:51 41m 24s 4 2017-09-12 00:04:59 2017-09-12 00:44:31 39m 32s 5 2017-09-12 00:04:57 2017-09-12 00:39:41 34m 44s 6 2017-09-12 00:07:51 2017-09-12 00:47:12 39m 21s 7 2017-09-12 00:06:11 2017-09-12 00:40:13 34m 2s 8 2017-09-12 00:05:30 2017-09-12 00:46:52 41m 22s
Comments
Post a Comment