【问题标题】:R: get the percentage of day comprised between two timestampsR:获取两个时间戳之间的天百分比
【发布时间】:2021-05-05 14:49:28
【问题描述】:

我正在尝试获取两个时间戳之间包含的一天的百分比。

就我而言,我有以下时间戳:2020-05-03 23:30:042020-05-03 23:43:37

所以我的间隔是 13 分钟,这意味着一天中大约 0.9%。

我该如何计算?

【问题讨论】:

    标签: r timestamp


    【解决方案1】:

    好的,所以我想出了这个解决方案(在数据框的情况下):

    timeseries= timeseries %>% 
      dplyr::mutate(diff_min = difftime(tsEnd,tsBegin,units="mins"),
                    percentage_day = (diff_min / 1440) * 100)
    

    其中tsBegin 包含2020-05-03 23:30:04 并且tsEnd 包含2020-05-03 23:43:37

    我将分钟差除以1440,因为这是一天中的分钟数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-08
      • 2018-05-29
      • 2023-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-22
      相关资源
      最近更新 更多