r - 将带有“x 小时 y 分钟”的时间格式转换为数字
问题描述
我有一个变量表示事件发生后的时间,它的编码如下:
time_since_event <- c("18 m", "56 m", "2 h 30 m", "18 h 2 m")
我希望它是数字并始终指示事件发生后的分钟数:
time_since_event_min <- c(18,56,150,1082)
解决方案
您可以使用lubridate
功能:
library(lubridate)
(time_since_event %>% toupper %>% period %>% period_to_seconds())/60
#[1] 18 56 150 1082
推荐阅读
- firebase - 如何使用颤振在 Firestore 中的文档内添加地图?
- php - 如果高级自定义字段中的值满足特定条件,则显示额外文本
- methods - 当您返回要从方法列表中删除的对象/基元时,描述的技术方法是什么?
- vue.js - 如何在 nuxt js 中设置默认翻译 i18n?
- ios - 金属着色器中包含的内容
- javascript - 剪刀石头布不会打印获胜条件
- asterisk - Issabel:如何在呼叫中心模块中将呼叫连接到代理之前向呼叫者播放预先录制的消息?
- google-apps-script - Google表格-填充单元格IF列的脚本包含
- excel - Excel 查找特定实例并附加到 URL 字符串的末尾
- r - 使用 min 函数根据列比较创建新数据