On 10-Aug-07 18:05:50, Lanre Okusanya wrote: > Hello all, > > I am working with a 1000x1000 matrix, and I would like to return a > 1000x1000 matrix that tells me which value in the matrix is greater > than a theshold value (1 or 0 indicator). > i have tried > mat2<-as.matrix(as.numeric(mat1>0.25)) > but that returns a 1:100000 matrix. > I have also tried for loops, but they are grossly inefficient. > > THanks for all your help in advance. > > Lanre
Simple-minded, but: > S<-matrix(rnorm(25),nrow=5) > S [,1] [,2] [,3] [,4] [,5] [1,] -0.9283624 -0.44418487 1.1174555 1.9040999 -0.4675796 [2,] 0.2658770 -0.28492642 -1.2271013 -0.5713291 1.8036235 [3,] 0.7010885 -0.42972262 0.7576021 0.3407972 -1.0628487 [4,] -0.2003087 0.87006841 0.6233792 -0.9974902 -0.9104270 [5,] 0.2729014 0.09781886 -1.0004486 1.5987385 -0.4747125 > T<-0*S > T[S>0.25] <- 1+0*S[S>0.25] > T [,1] [,2] [,3] [,4] [,5] [1,] 0 0 1 1 0 [2,] 1 0 0 0 1 [3,] 1 0 1 1 0 [4,] 0 1 1 0 0 [5,] 1 0 0 1 0 Does this work OK for your big matrix? HTH Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <[EMAIL PROTECTED]> Fax-to-email: +44 (0)870 094 0861 Date: 10-Aug-07 Time: 19:50:37 ------------------------------ XFMail ------------------------------ ______________________________________________ R-help@stat.math.ethz.ch 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.