Skip to content

row sum question

3 messages · Keun-Hyung Choi, jim holtman, Gabor Grothendieck

#
Will this do it for you:
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]    1    0    1    1    1    0    0    0    0     0
 [2,]    0    0    0    0    0    0    0    1    1     0
 [3,]    0    1    0    0    1    1    1    1    1     1
 [4,]    0    1    1    1    0    0    0    0    1     1
 [5,]    0    0    1    0    1    1    1    0    0     0
 [6,]    1    0    1    0    0    0    1    0    0     0
 [7,]    0    0    1    0    0    1    0    0    1     1
 [8,]    1    0    1    0    0    0    1    1    1     0
 [9,]    0    1    0    1    0    1    1    0    0     0
[10,]    0    1    1    1    1    0    0    0    1     0
+     print(sum(mask & mat[i,]))
+     mask <- mask & !mat[i,]
+ }
[1] 4
[1] 2
[1] 4
[1] 0
[1] 0
[1] 0
[1] 0
[1] 0
[1] 0
[1] 0
On Sun, Dec 21, 2008 at 8:36 PM, Keun-Hyung Choi <khchoi at sfsu.edu> wrote:

  
    
#
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: