I would create a column for each group showing the latest value for that group. Then just sum those columns:
library(zoo)
result <- rep(0, nrow(dt))
for(g in dt[, unique(group)]) {
result <- result + dt[, na.fill(na.locf(ifelse(group==g, 1, NA)*value, na.rm=F), 0)]
}
all(dt[, desired] == result)