Search code examples
rtimedifftime

R difftime define units to use


I'm trying to calculate the time of various processes but they vary between 10 seconds and ten minutes and I'd like them to be in common terms (ie all minutes).

When I run this code I would expect it to returns in minutes but it returns in seconds:

time1 <- Sys.time()
time2 <- Sys.time()
elapsedTime <- as.difftime(time2 - time1 , units = 'mins')
print(elapsedTime )

Time difference of 1.227549 secs

Any suggestions for how I'd get this in minutes?


Solution

  • Use the actual difftime function instead of as.difftime

    difftime(time2, time1 , units = 'mins')
    
    time1 <- Sys.time()
    time2 <- Sys.time()
    difftime(time2, time1 , units = 'mins')
    
    [1] Time difference of 0.06004666 mins