I have a file containing, multiple rows as follows
In file1:
a 8|2|3|4 4
b 2|3|5|6|7 5
c 8|5|6|7|9 5
a to a has 4 overlaps, similarly a to b had 2 overlaps, so to check the overlaps between various entity, I need to generate a matrix with the above details, and the output should be a matrix like
a b c
a 4 2 1
b 2 5 3
c 1 3 5
Please give me a suggestion, how to do this? Is there any way to do this using excel or using a shell script or using R? I have written this following code but since I am not a good coder, I couldn't get the output printed in a right format.
setwd('C:\\Users\\Desktop\\')
newmet1<-file("file.txt")
newmet2<-strsplit(readLines(newmet1),"\t")
Newmet<-sapply(newmet2, function(x) x[2:length(x)], simplify=F )
for (i in 1:length(Newmet))
{
for (j in 1:length(Newmet)
{
c <- ((intersect(Newmet[[i]], Newmet[[j]]))
print (length(c))
}
}
Edited: Thanks for all the answers.. I got the matrix using both excel and R with the help of following answers.