首页 > 解决方案 > 选择日期/时间单元格时如何强制 R 保持时间值?

问题描述

我有一列日期/时间值,我正在选择顶部单元格和底部单元格:

> time1 <- Angels.rolling$date.hour[1]
> time1
[1] "2014-02-17 UTC"
> time2 <- Angels.rolling$date.hour[(nrow(Angels.rolling))]
> time2
[1] "2018-02-14 01:00:00 UTC"

time1 应该显示为“2014-02-17 00:00:00 UTC”,因为这是顶部单元格的值,但它似乎删除了时间,因为它是午夜。该列已使用 lubridate 的 ymd_hms() 格式化。

如何在不丢失数据的情况下将整个日期和时间值拉入我的 time1 变量?

标签: r

解决方案


The time is still in the object, it's just not printed by default. If you want the time to be printed you can use format.

format(Angels.rolling$date.hour[1], '%Y-%m-%d %T %Z')

推荐阅读