DT <- data.table(data, key = c("ID", "t")) I think "ID" and "t" should be replaced with IDvar and tvar