I use this example in order to understand the diff function.
Usually, the diff function computes the difference between pairs of consecutive elements of a numeric vector.
What is happening in the following example?
test <- data.table(X = c(4, 15)[round(runif(20, 1, 2))],
Y = c(45, 93)[round(runif(20, 1, 2))],
Time = sort(sample(1:30, 20)))
test[ , diff(Time), c("X", "Y")]