If your data is already sorted (and preferably in a character
format, factor
could cause problems with the levels) , then you could use something like this
#add preceding row cap_end entry:
dt$prev_CAP_END <- c(NA,head(dt$CAP_END,-1))
#wherever missing, update with prevcap_end
dt[which(is.na(dt$CAP_START)),"CAP_START"] <- dt[which(is.na(dt$CAP_START)),"prev_CAP_END"]