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]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.