[R] print points from a huge matrix

Roger Bivand Roger.Bivand at nhh.no
Tue Aug 12 16:16:53 CEST 2003


On Tue, 12 Aug 2003, Bing Zhang wrote:

> Hi All,
> 
> I have a 8000*8000 matrix and I want to print out a file with the row name, 
> column name and the value for those point with values satisfying a condition. 
> I tried using a for loop, however, it took me forever to get the result. Is 
> there a fast way to do this? Thanks!
> 

> aa <- matrix(rnorm(1000000), 1000, 1000)
> found <- which(aa > 4, arr.ind=TRUE)
> cbind(found, aa[found])

(for your condition) should do it. My matrix is a bit smaller though, but 
it goes quite fast. If you need the row/col names, you'll want to make 
some other structure than the cbind (as a data frame with character 
columns).

> Bing
> 
> ---------------------------------
> 1060 Commerce Park
> Oak Ridge National Laboratory
> P.O. Box 2008, MS 6480
> Oak Ridge, TN 37831-6480
> Phone: 865-241-0761
> Email: zhangb at ornl.gov
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: Roger.Bivand at nhh.no




More information about the R-help mailing list