a question related to nested R loop
1
0
Entering edit mode
aiguo li ▴ 10
@aiguo-li-3989
Last seen 9.6 years ago
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
• 669 views
ADD COMMENT
0
Entering edit mode
@benilton-carvalho-1375
Last seen 4.1 years ago
Brazil/Campinas/UNICAMP
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 >
ADD COMMENT

Login before adding your answer.

Traffic: 863 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6