quote: > x <- c(1, 2, 3, NA, 5, 6, 7, 8, 9, 10) > rev(cumsum(rev(is.na(x)))) [1] 1 1 1 1 0 0 0 0 0 0 A more natural way to do this is > cumsum(is.na(c(NA,x[-length(x)]))) [1] 1 1 1 1 2 2 2 2 2 2 endquote
Both of which suggest the original problem could also be dealt with by using rle(). Something like
xna<-is.na(x) rle(xna) and then apply cumsum to sections of x based onthe lengths returned by rle Carl ______________________________________________ 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.