Skip to content
Prev 258436 / 398502 Next

threshold matrix

On Fri, Apr 29, 2011 at 07:44:59AM -0700, Alaios wrote:
Hi.

This may be avoided, for example

  M2 <- M
  M2[, ] <- as.numeric(M >= thresh)

or

  array(as.numeric(M >= thresh), dim=dim(M))
If A and B are matrices of the same dimension, then

  A == B

is a logical matrix with TRUE entires for positions, where 
A and B match exactly.

  abs(A - B) <= eps

is a logical matrix with TRUE entires for positions, where
A and B differ at most by eps.

If you want to get only one logical result, then use

  all(A == B)

for exact equality and

  all(abs(A - B) <= eps)

for approximate equality of all entries.

See also ?all.equal, which uses the relative error, not absolute
difference.

Hope this helps.

Petr Savicky.