Question: I want to add greater then and lessthen condition in below example. is it possible?
[![enter image description here](https://i.stack.imgur.com/rSzsf.png)](https://i.stack.imgur.com/rSzsf.png)

Answer: 
"you want to use diff function to take the time differences between a VECTOR elements, only in the units specified"

pls try below code : (by int\_diff function)

```
> VECTOR = c(ymd_hms("2016-05-10 16:17:03"),
+            ymd_hms("2016-05-10 16:17:04"),
+            ymd_hms("2016-05-10 17:19:33"),
+            ymd_hms("2016-05-10 19:55:03")
+ )
> as.numeric(int_diff(VECTOR))
[1]    1 3749 9330
> round(as.numeric(int_diff(VECTOR))/3600,2)
[1] 0.00 1.04 2.59

```

see, whatever the time interval min unit is seconds or not, it is always scaled by seconds as below.

```
> VECTOR = c(ymd_hms("2016-05-10 16:17:03"),
+            #ymd_hms("2016-05-10 16:17:04"),
+            ymd_hms("2016-05-10 17:19:33"),
+            ymd_hms("2016-05-10 19:55:03")
+ )
> as.numeric(int_diff(VECTOR))
[1] 3750 9330
> round(as.numeric(int_diff(VECTOR))/3600,2)
[1] 1.04 2.59

```
I wrote two functions in case anyone might find useful.

```
timeDiffUnitConvert = function(Diffs, to="day", roundingN = 1){      
  if(to == "day"){
    R = round(as.numeric(as.duration(Diffs))/3600/24,roundingN)
  } else if (to == "hour") {
    R = round(as.numeric(as.duration(Diffs))/3600, roundingN)
  } else if (to == "min") {
    R = round(as.numeric(as.duration(Diffs))/60, roundingN)
  } else if (to == "sec"){
    R = round(as.numeric(as.duration(Diffs)), roundingN)
  } else {
    stop("to which unit? it must be `day`, `hour`, `min` or `sec`.")
  }
  R
}

timeDiffVector = function(TimeVector, to="day", roundingN = 1, attachNaMode = "none"){
  R = timeDiffUnitConvert(diff(TimeVector), to = to, roundingN = roundingN)
  if(attachNaMode == "leading"){
    R = c(NA,R)
  } else if(attachNaMode == "trailing"){
    R = c(R,NA)
  } else{
    stop("check your attachNaMode: shall be either `leading` or `trailing`")
  }
  R
}

```