【问题标题】:R - How to convert a column times in ####M #S format to just number of minutesR - 如何将####M #S格式的列时间转换为分钟数
【发布时间】:2019-03-17 12:37:04
【问题描述】:

我已经使用 lubridate 创建了一列时间格式 ####M ##S

df$delay <- minutes(df$finish-Delays$start)

我怎样才能将此列转换为仅在分钟前给出数字####?

感谢您的帮助。

【问题讨论】:

    标签: r time lubridate


    【解决方案1】:

    看看 S4 插槽...

    library(lubridate)
    
    # create data
    df <- data.frame(finish = 20)
    Delays <- data.frame(start = 10)
    (df$delay <- minutes(df$finish-Delays$start))
    [1] "10M 0S"
    
    # take a look at the 'delay' object
    str(df$delay)
    Formal class 'Period' [package "lubridate"] with 6 slots
      ..@ .Data : num 0
      ..@ year  : num 0
      ..@ month : num 0
      ..@ day   : num 0
      ..@ hour  : num 0
      ..@ minute: num 10
    
    # access the 'minute' slot
    df$delay@minute
    [1] 10
    

    【讨论】:

      猜你喜欢
      • 2020-10-14
      • 1970-01-01
      • 1970-01-01
      • 2019-01-28
      • 2012-04-22
      • 1970-01-01
      • 2020-10-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多