I have the following program:
timeStart<-Sys.time()
timeEnd<-Sys.time()
difference<-timeEnd-timeStart
anyVector<-c(difference)
at the end I need to put that data into a vector, the problem that I have is than when the difference is in seconds the value is like:
4.46809 seconds
and when it passes some minutes the values is like:
2.344445 minutes
I would like that the answer is converted to minutes in any case, but when I do something like this:
anyVector<-c(difference/60)
for the case that the value of the difference is in seconds work fine, but it will also transform the data when is in minutes giving me an incorrect number.
So, how I can convert to minutes only when the answer is in seconds and not where is in minutes already?
You can do it with the difftime
function from base R:
timeStart<-Sys.time()
timeEnd<-Sys.time()
difference <- difftime(timeEnd, timeStart, units='mins')
Output
> difference
Time difference of 0.1424748 mins
You just specify the units
argument and set it to mins
and the output will always be in minutes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With