【发布时间】:2021-04-05 16:25:53
【问题描述】:
我的代码读入一个 .txt 文件,该文件在一列中包含一系列时间戳。我需要为该列考虑夏令时,所以我使用 lubridate 包从这些时间戳中减去一个小时。我正在努力将周期类从 lubridate 转换回 %I:%M%:S %p 的时间格式。
这是我的代码。
# Changing from 24 Hr to 12 Hr Format #
raw_data_sample$Time <- format(strptime(raw_data_sample$Time, format='%H:%M:%S'), '%I:%M:%S %p')
# Subtracting an Hour for Daylight Savings
raw_data_sample$Time <- hms(raw_data_sample$Time)
raw_data_sample$Time <- raw_data_sample$Time - hours(1)
这是我当前的输出。
c("1H 41M 54S", "1H 42M 4S", "1H 42M 14S", "1H 42M 31S", "1H 42M 41S", "1H 43M 1S")
我希望得到类似的输出
1:41:54 PM, 1:42:40 PM
有什么建议吗?谢谢!
【问题讨论】: