0

The result of the following instruction:

as.difftime("5 11:04:36", "%d %H:%M:%S", units =("mins"))

is

Time difference of -7975.4 mins

It seems that this function is calculating the time difference between Sys.Time() and the given value. I actually need an object to store a time span value extracted from a string (). Am I using the wrong function or is it not the right way of using it?

Sotos
  • 51,121
  • 6
  • 32
  • 66
michele74c
  • 63
  • 11
  • 2
    Welcome to StackOverflow! Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269). This will make it much easier for others to help you. – Sotos Sep 11 '17 at 06:32
  • Time *span* requires two date-times. Where is your second date-time? – CPak Sep 11 '17 at 12:38
  • @CPak that's the question. The value I want to store is itself a span. The question is just: which R object can store a time span? Does it exist? – michele74c Sep 11 '17 at 14:21
  • Are `lubridate` classes what you're looking for? – CPak Sep 11 '17 at 20:24
  • Sorry for the late reply @CPak. I think that replacing some characters with time units, the Duration class is what I was searching for. – michele74c Sep 11 '17 at 20:29
  • Ok, good to know. Could I ask: why are these classes preferred to a `Date` class? – CPak Sep 11 '17 at 20:33
  • @CPak because the value is a time interval. A Date implies useless information (year, month, etc...) that make unclear the data set – michele74c Sep 12 '17 at 05:35

1 Answers1

0

Look into lubridate

I think you want something like Duration-class, Period-class, or Timespan-class

# Duration
dur <- duration(hours = 10, minutes = 6)
# [1] "36360s (~10.1 hours)"

# Period
per <- period(hours = 10, minutes = 6)
# [1] "10H 6M 0S"
CPak
  • 13,260
  • 3
  • 30
  • 48