# [R] print points from a huge matrix

Bing Zhang bih at ornl.gov
Tue Aug 12 18:15:41 CEST 2003

```Thanks. I made it. For those who have the same problem, here is my data:
> corr2
100002_at   100003_at  100004_at   100005_at
100002_at  1.00000000 -0.08452797 -0.2977039 -0.10522948
100003_at -0.08452797  1.00000000 -0.2955658  0.02353673
100004_at -0.29770388 -0.29556577  1.0000000  0.20758195
100005_at -0.10522948  0.02353673  0.2075820  1.00000000
100006_at -0.20549685  0.15661089 -0.2132440 -0.48680542
and here is how I did it:
> found2<-which(abs(corr2)>0.8, arr.ind=TRUE)
> cbind(rownames(corr2)[found2[,1]],colnames(corr2)[found2[,2]],corr2[found2])
[,1]        [,2]        [,3]
[1,] "100002_at" "100002_at" "1"
[2,] "100003_at" "100003_at" "1"
[3,] "100004_at" "100004_at" "1"
[4,] "100005_at" "100005_at" "1"

>===== Original Message From Roger.Bivand at nhh.no =====
>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

---------------------------------
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

```

More information about the R-help mailing list