Conditionally, when Ind of a certain row is 1, want to get sum or delta of Val in that row and 1 row above.
Val Ind Val Ind Del 10 0 10 0 NA 11 0 11 0 NA 13 1 -------> 13 1 24 or 2 16 0 16 0 NA A simple way I guess is to get shifted vector of Val (say, c(NA, 10, 11, 13)), add to or minus from Val, then and logically AND with Ind. Which function provides the shift operation of the vector Val? Also welcomed if any better way to do this. Thanks. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.