[BioC] a question related to nested R loop

Benilton Carvalho beniltoncarvalho at gmail.com
Wed Mar 24 00:13:52 CET 2010


set.seed(1)
x = matrix(sample(c(T, F), 16, rep=T), nc=4)
colnames(x) = rownames(x) = letters[1:4]
f = function(i) c(rownames(x)[i[1]], colnames(x)[i[2]])
tmp = apply(which(x, TRUE), 1, f)
t(tmp)

b

On Mon, Mar 22, 2010 at 4:43 PM, aiguo li <li9212001 at yahoo.com> wrote:
> Hi all,
>
> I have a logical index matrix now and need to create a two column matrix that contains the row.names and col.names of this matrix where the logical index is TURE.
>
> The logical matrix is like this:
>
>       Gene2   Gene1  Gene3
> Gene1  TRUE    TRUE   FALSE
>
> Gene2 FALSE   TRUE   FALSE
>
> Gene3 FALSE   FALSE  TRUE
>
> to create a list:
>
> Gene1 Gene2
> Gene1 Gene1
> Gene2 Gene1
> Gene3 Gene3
>
> Here is my codes, which seems not working properly.
> m=0;
> for(i in 1:2909){
>        for(j in 1:2909)
>        {
>        if(a[i,j]==TRUE)
>        GeneA[m]<-row.names(d)[i];
>        GeneB[m]<-row.names(d)[j]
>        m=m+1;
>        }
>        }
>
> Thanks,
>
> Anna
>
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor
>



More information about the Bioconductor mailing list