Skip to content
Prev 165336 / 398506 Next

row sum question

Assuming DF is a data frame like this:

DF <- data.frame(V1 = c(1, 0, 1, 0), V2 = c(1, 1, 1, 1),
    V3 = c(0, 1, 1, 1), V4 = c(0, 0, 0, 1))

# try this:

head(rowSums((rbind(0, cummax(DF)) < rbind(cummax(DF), 0))), -1)
On Sun, Dec 21, 2008 at 8:36 PM, Keun-Hyung Choi <khchoi at sfsu.edu> wrote: