[R] need help to generate an intersection matrix
Li, Aiguo (NIH/NCI) [E]
liai at mail.nih.gov
Thu Feb 2 20:54:43 CET 2017
Dear all,
I am new to r script and run into some difficulty with this simple task.
Here is my data: I need to find out the number of mutual intersected elements as shown below
data
pathway1 A B C D E
pathway2 A C F
pathway3 B D E
output
pathway1 pathway2 pathway3
pathway1 5 2 3
pathway2 2 3 0
pathway3 3 0 3
here is my script
tb = matrix(data =NA, nrow = 3, ncol = 3)
for(i in 1:3){
for(j in 1:3){
tb[i,j]=length(intersect(data[i,][!is.na(data[i,])], data[j,][!is.na(data[j,])]))
}
}
Ana
[[alternative HTML version deleted]]
More information about the R-help
mailing list