Using the following dataset, what is the fastest way to compute for each ID (Col1) the difference with all the other ID02 (Col2) within the same time (Col3, t
) without using dplyr
, (data.table
welcome!)? Note that the difference should be taken only between ID and ID2 such that ID is different from ID2 (this does not happen in the first row of the data.frame for instance).
df <- data.frame(ID = rep(rep(c(1,2,3,4),3),2), ID2 = rep(c(c(1,rep(5,3)), rep(6,4), \\
rep(7,4)),2), t = c(rep(1,12), rep(2,12)), value = runif(12) )
The difference should be taken over the column value
.