understanding diff function

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")]

It produces the (lagged) differences of Time values by group of X, Y pairs.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.