将给定字符串转换为分钟(Convert the Given String to Minutes)
我有一个以String格式表示时间的列。 格式为PT5H1M15S which is equivalent to 5 Hour 1 Minute and 15 Second(Pacific Time) 。 我是R的新手,需要将其转换为Minutes。 任何帮助在这里表示赞赏。 谢谢。
我的预期答案是301.25分钟
I have a column with the time in String format. The format is PT5H1M15S which is equivalent to 5 Hour 1 Minute and 15 Second(Pacific Time). I am new to R and need to convert this to Minutes. Any help here is appreciated. Thanks.
My expected answer is 301.25 Minutes
最满意答案
我们可以使用lubridate
library(lubridate) period_to_seconds(hms(str1))/60 #[1] 301.25要么
as.numeric(hms(str1))/60 #[1] 301.25数据
str1 <- "PT5H1M15S"We can use lubridate
library(lubridate) period_to_seconds(hms(str1))/60 #[1] 301.25Or
as.numeric(hms(str1))/60 #[1] 301.25data
str1 <- "PT5H1M15S"更多推荐
发布评论