I have a matrix with x columns and y rows. x and y are large values.
              A           B      C         
GeneA         1           0      0        
GeneB         0           0      1
GeneC         0           0      1
GeneD         1           0      1
I want to apply a distance function over rows of the matrix and output a matrix with dimension y*y with each cell having the return value from the function. Output looks like this:
               GeneA        GeneB     GeneC   GeneD       
GeneA            1.0           0.7     0.0       0.4 
GeneB            0.6         0.2     1.0       1.0
GeneC            0.0         0.1     1.0       0.5
GeneD            1.0         0.5     0.1       0.8
My function is:
dist <- function(vec1, vec2) {
  res=length(intersect(vec1,vec2))/length(union(vec1,vec2))
  return (res)
}
 
    