[R] how to threshold a matrix

Gabor Grothendieck ggrothendieck at gmail.com
Sat Dec 15 17:10:06 CET 2007


Try:

(M >= 0.3) - (M <= 0.3)

On Dec 15, 2007 10:56 AM, affy snp <affysnp at gmail.com> wrote:
> Dear list,
>
> I have a matrix M (2500 rows and 9 columns). It looks like
>
> 2.2     0.1      2.6    3.6 ......
> 0.4     1.9      2.7    4.2......
> 1.8     2.5      4.3    2.2.......
> .....................
>
> If I want to do:
>
> (1) if M[i,j]>=0.3, M[i,j]=1
> (2) if M[i,j]<=-0.3, M[i,j]=-1
> (3) Otherwise, M[i,j]=0
>
> Is there a way to ceil and floor the data?
>
> Thanks a lot!
>
> Allen
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list