2016-11-08 111 views
1

我需要将一天中的时间(例如13:34)转换为分钟数或分钟数,因此预期的答案是(780 + 34)或814分钟将时间转换为总分钟数的R函数

我正在考虑将小时和分钟提取到可能使用lubridate的变量中,当然还需要将小时数乘以60并添加分钟数。

但是有没有一种方法或函数可以用于这个已经存在的?以为我会检查SO社区。

感谢

回答

1

感谢RAWR - 提供POSIX类型的答案是工作得很好:

difftime(as.POSIXct('13:34', format = '%H:%M'), as.POSIXct('00:00', format = '%H:%M'), units = 'min') 

给大家这里是我得到的输出:

z<-difftime(as.POSIXct('13:34', format = '%H:%M'), as.POSIXct('00:00', format = '%H:%M'), units = 'min') 

#print out z 
> z 

#response 
Time difference of 814 mins 

#confirm that z only has the 814 as value 
> typeof(z) [1] "double"