Re: [R] threshold matrix

From: Rolf Turner <rolf.turner_at_xtra.co.nz>
Date: Sat, 30 Apr 2011 13:07:54 +1200

On 30/04/11 02:44, Alaios wrote:
> Thanks a lot.
> I finally used
>
> M2<- M
> M2[M< thresh]<- 0
> M2[M>= thresh]<- 1
>
> as I noticed that this one line
>
> M2<- as.numeric( M[]< thresh )
> vectorizes my matrix.
>
> One more question I have two matrices that only differ slightly. What will be the easiest way to compare and find the cells that are not the same?

(1) M2 <- 0 +(M >= thresh)

is one line (and is sexier! :-) ).

(2) which(A !=B, arr.ind = TRUE)

or (possibly more sensibly)

     which (abs(A-B) > sqrt(.Machine$double.eps), arr.ind = TRUE)

should solve your ``One more question''.

     cheers,

         Rolf Turner



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sat 30 Apr 2011 - 01:13:32 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 30 Apr 2011 - 01:20:35 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive