Re: [R] threshold matrix

From: David Winsemius <>
Date: Fri, 29 Apr 2011 09:57:44 -0400

On Apr 29, 2011, at 9:37 AM, Alaios wrote:

> Dear all,
> I have a quite big matrix which I would like to threshold.
> If the value is below threshold the cell should be zero
> and
> if the value is over threshold the cell should be one

M2 <- M
M2[M < thresh] <- 0
M2[M >= thresh] <- 1

or perhaps simply:

M2 <- as.numeric( M[] < thresh )
> One really simple way to do that is two have a nested loop and check
> cell by cell.
> The problem is that this seems to be really time consuming and
> ineficient.
> What do you suggest me to try out?


David Winsemius, MD
West Hartford, CT

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Fri 29 Apr 2011 - 14:10:50 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 Fri 29 Apr 2011 - 15:00:34 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive