Here's another option using a sliding join after creating a lookup table
indx <- data.table(unique(dt[ ,.(loc.x, loc.y)]), time = test.day) dt[indx, roll = TRUE, on = names(indx)]
Or a very similar option suggested by @eddi
dt[dt[, .(time = test.day), by = .(loc.x, loc.y)], roll = T, on = c('loc.x', 'loc.y', 'time')]
Or one liner that will be less efficient, as it will call [.data.table by group
dt[, .SD[data.table(test.day), value, roll = TRUE, on = c(time = "test.day")], by = .(loc.x, loc.y) ]
David Arenburg
source share