Hi all,
I have a dataframe with a time column having values like "0s" "300s (~5 minutes)" "600s (~10 minutes)" "900s (~15 minutes) "14400s (~4 hours)" "14700s (~4.08 hours)" "15000s (~4.17 hours)" "15300s (~4.25 hours)"etc. I would like to display it in hours minutes second format (eg:12H 05M 0S).
Any help would be highly appreciated.
Hi @sitaram , try to put an example of data for better get help.
See this guide:
A minimal reproducible example consists of the following items:
A minimal dataset, necessary to reproduce the issue
The minimal runnable code necessary to reproduce the issue, which can be run
on the given dataset, and including the necessary information on the used packages.
Let's quickly go over each one of these with examples:
Minimal Dataset (Sample Data)
You need to provide a data frame that is small enough to be (reasonably) pasted on a post, but big enough to reproduce your issue.
Let's say, as an example, that you are working with the iris data frame
head(iris)
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1 5.1 3.5 1.4 0.…
This converts the character vector into Date objects, from which you can use format
library(lubridate)
#>
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#>
#> date, intersect, setdiff, union
the_times <- c("0s", "300s (~5 minutes)",
"600s (~10 minutes)",
"900s (~15 minutes)",
"14400s (~4 hours)",
"14700s (~4.08 hours)",
"15000s (~4.17 hours)",
"15300s (~4.25 hours)")
begin <- Sys.Date()
(the_seconds <- as.numeric(gsub("s.*$","",the_times)))
#> [1] 0 300 600 900 14400 14700 15000 15300
full_datetimes <- (begin + seconds(the_seconds))
format(full_datetimes, format = "%H:%M:%S")
#> [1] "00:00:00" "00:05:00" "00:10:00" "00:15:00" "04:00:00" "04:05:00" "04:10:00"
#> [8] "04:15:00"
Created on 2023-03-15 with reprex v2.0.2
system
Closed
April 26, 2023, 8:38pm
4
This topic was automatically closed 42 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.