r - R:以秒为单位的变量“difftime”转换为以天为单位的变量“difftime”
问题描述
我有以下x
类向量,difftime
以秒为单位表示一些时间跨度:
> x
Time differences in secs
[1] 0 0 7948800 0
> class(x)
[1] "difftime"
我想转换变量以便以天而不是秒来表示每个值
我怎么能得到它?
解决方案
要么units=
按照 RonakShah 的建议使用,
x <- difftime(Sys.time() + c(0, 100, 3*86400), Sys.time(), units = "days")
x
# Time differences in days
# [1] 0.000000000 0.001157407 3.000000000
或事后更改单位。
x <- difftime(Sys.time() + c(0, 100, 3*86400), Sys.time())
x
# Time differences in secs
# [1] 0 100 259200
units(x) <- "days"
x
# Time differences in days
# [1] 0.000000000 0.001157407 3.000000000
推荐阅读
- postgresql - 使用 Helm 3 在 Kubernetes 上安装 PostgreSQL
- css - 无法在表格标题中居中文本和图像
- docker - 通过 dockerfile 为我们的容器添加用户管理
- prometheus - Grafana:在统计面板的标题字段中使用实例标签
- javascript - 在另一个里面访问 jest.fn 函数
- java - Java lambda 表达式最佳实践
- tensorflow - 我有一个 NVIDIA Quadro 2000 显卡,我想安装 TensorFlow。它会起作用吗?
- node.js - Git/node 卡在旧的 .js 文件版本上
- python - 通过 APSCHEDULER 在 python 中安排一个 cron 作业以每次在 1 和 31 分钟运行一个 python 脚本
- sql - 需要在oracle sql中获取上一财年数据