How to convert time to decimal

后端 未结 3 1972
难免孤独
难免孤独 2020-12-03 20:11

I have a large data set containing time in hh:mm:ss format and I would like to convert these to a decimal format while ignoring the hours (hh). I have used strptime but this

3条回答
  •  抹茶落季
    2020-12-03 20:47

    There is probably a lubridate function for this, but I'd do it like this:

    x <-  "01:18:30"
    
    y <- (as.numeric(as.POSIXct(paste("2014-01-01", x))) - 
       as.numeric(as.POSIXct("2014-01-01 0:0:0")))/60
    #[1] 78.5
    

    Ignoring the hours:

    y%%60
    #[1] 18.5
    

提交回复
热议问题