This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Combine conditions between two matrices of the same size

I have produced two matrices of the same size using R, from a microarray tsv file. One matrix with the log2FC of every gene in each of the 5 conditions and one matrix with the p.adjusted value of every gene in each of the 5 conditions. My goal is to find the genes that satisfy both the conditions log2FC>1 and p.adj<=0.05. I have tried the following:

con1<-matrix(which(log2FC>1|log2FC<(-1)))
con1

con2<-matrix(which(padj<=0.05))
con2

uu<-sapply(1:nrow(con1), function(i){
  x<-con1[i]
  which(x==con2)
})
uu1<-matrix(uu)

and the outcome is a list of the cells of con2 where the two conditions meet. However this is not very helpful as my goal is to create a matrix of genes that satisfy both conditions. I also tried

con1<-which((log2FC>1|log2FC<(-1)), arr.ind = TRUE, useNames = TRUE)

con2<-which((padj<=0.05),arr.ind = TRUE, useNames = TRUE)

which(rownames(con2)==rownames(con1))

but didn't work either.

Any thoughts?

r padjval log2fc conditions

I also tried duplicated

hh<-duplicated(rbind(con1,con2))
hh1<-as.matrix(hh)

but the outcome is just the rowanmes, not the entire row.

1 answer

For anyone who might face the same problem since the matrices are of the same size.

which( ( (logFC>=1) | (logFC <= -1) ) & (pvadj<=0.05), arr.ind = TRUE, useNames = TRUE)

Log in to answer this question.