Skip to content
Prev 61846 / 398498 Next

count element in column

On 05-Jan-05 Frederic renaud wrote:
If there is only one column, then either

  sum(x<0)

or

  sum(x[,1]<0)

If there is more than one column, then

  sum(x[,1]<0)
  sum(x[,2]<0)
  ...

does it for each column, one at a time, and

  colSums(x<0)

does it for all the columns at once (but separately), while

  sum(x<0)

does it for the whole matrix (without regard for columns).

Best wishes,
Ted.


--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861  [NB: New number!]
Date: 05-Jan-05                                       Time: 17:43:03
------------------------------ XFMail ------------------------------