0

Taking into account the following matrix:

      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [,15] [,16] [,17] [,18] [,19] [,20]
 [1,]    2    0    0    0    0    0    0    0    0     0     0     0     0     0     0     0     0     0     0     0
 [2,]    2    2    0    0    0    0    0    0    0     0     0     0     0     0     0     0     0     0     0     0
 [3,]    2    4    2    2    2    2    2    2    4     8     6     6     4     4     6     4     4     2     2     2
 [4,]    2    2    2    4    4    0    0    0    0     0     0     0     0     0     0     0     0     0     0     0
 [5,]    4    4    4    4    6    6    6    6    6     2     2     0     0     0     0     0     0     0     0     0
 [6,]    4    4    4    2    2    2    4    6    6     2     2     2     2     2     2     2     2     2     0     0
 [7,]    4    2    0    0    0    0    0    0    0     0     0     0     0     0     0     0     0     0     0     0
 [8,]    4    6    4    6    4    6    4    4    6     2     2     0     0     0     0     0     0     0     0     0
 [9,]    0    0    0    0    0    0    0    0    0     0     0     0     0     0     0     0     0     0     0     0
[10,]    4    6    4    4    6    8   14   10   14     8    10     8     8     6     6     4     0     0     0     0
[11,]    2    2    2    2    2    2    0    0    0     0     0     0     0     0     0     0     0     0     0     0
[12,]    2    2    4    4    2    2    2    2    0     0     0     0     0     0     0     0     0     0     0     0
[13,]    2    2    2    0    0    0    0    0    0     0     0     0     0     0     0     0     0     0     0     0
[14,]    0    0    0    0    0    0    0    0    0     0     0     0     0     0     0     0     0     0     0     0
[15,]    0    0    0    0    0    0    0    0    0     0     0     0     0     0     0     0     0     0     0     0
[16,]    0    0    0    0    0    0    0    0    0     0     0     0     0     0     0     0     0     0     0     0
[17,]    2    4    6    4    2    2    0    0    0     0     0     0     0     0     0     0     0     0     0     0
[18,]    2    4    4    4    6    4    8   10    8    14    16    14    20    24    26    16    16    20    20    22
[19,]    2    4    2    2    4    4    4    2    4     2     2     2     2     2     2     2     0     0     0     0
[20,]    2    0    0    0    0    0    0    0    0     0     0     0     0     0     0     0     0     0     0     0 

How could I extract the total number of 0s from each column?

Radiodef
  • 37,180
  • 14
  • 90
  • 125
Jordan
  • 131
  • 8
  • 1
    Ask one question at a time and provide a reproducible example. Some guidance: http://stackoverflow.com/a/28481250/1191259 – Frank Oct 11 '15 at 15:00
  • 1
    `apply(trial, 1, function(x) Position(isTRUE, !as.logical(x)))` and `colSums(trial == 0)` methinks or `apply(m, 1, function(x) min(which(x == 0)))` would be more simple for 1) I just had `Position` on the mind – rawr Oct 11 '15 at 15:01
  • Your second option works much better for the kind of script I am running - thank you very much @rawr – Jordan Oct 11 '15 at 15:09

1 Answers1

3

Applying colSums(trial == 0) to the matrix gives a nice summary of the total number of 0s in each column

Jordan
  • 131
  • 8