title: Speed up for nested for loop using apply function
body: <p>I am not good in using apply family of functions.</p>
  
  <p>I want to use apply family of functions instead of following type of nested loop iterated by 9076 x 9076 times for computation speed up. Minimal reproducible data is given below. Please help.</p>
  
  <p>Data:</p>
  
  <pre><code>data = structure(list(C1 = structure(c(3L, 4L, 2L, 5L, 1L), .Label = c("GO:0001525", 
  "GO:0001869", "GO:0002576", "GO:0003723", "GO:0005515"), class = "factor"), 
      C2 = structure(c(2L, 3L, 1L, 4L, 5L), .Label = c("GO:0002020", 
      "GO:0003674", "GO:0003727", "GO:0005515", "GO:0005829"), class = "factor"), 
      C3 = structure(c(3L, 1L, 2L, 1L, 4L), .Label = c("", "GO:0002020", 
      "GO:0005576", "GO:0005886"), class = "factor"), C4 = structure(c(1L, 
      1L, 2L, 3L, 4L), .Label = c("", "GO:0002576", "GO:0005737", 
      "GO:0008201"), class = "factor")), class = "data.frame", row.names = c("A1BG", 
  "A1CF", "A2M", "AAGAB", "AAMP"))
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>if (!requireNamespace("BiocManager", quietly = TRUE))
  install.packages("BiocManager")
  BiocManager::install("GO.db", version = "3.8")
  BiocManager::install("GOSemSim", version = "3.8")
  BiocManager::install("org.Hs.eg.db", version = "3.8")
  BiocManager::install("annotate", version = "3.8")
  
  install.packages("cluster")
  install.packages("RUnit")
  
  # download csbl.go_1.4.1.tar.gz from http://csbi.ltdk.helsinki.fi/csbl.go/
  
  # R CMD INSTALL csbl.go_1.4.1.tar.gz
  
  library(org.Hs.eg.db)
  library(GO.db)
  library(GOSemSim)
  
  
  mat=matrix(,5,5)  %actual mat=matrix(,9076,9076)
  hsGO &lt;- godata('org.Hs.eg.db', ont="MF")
  
  for (i in 1:5) %actual for(i in 1:9076)
  {
  for (j in 1:5) %actual for(j in 1:9076)
  {
     a=as.matrix(data[i,1:ncol(data)])
     b=as.matrix(data[j,1:ncol(data)])
     a=a[a!=""]
     b=b[b!=""]
     mat[i,j]=mgoSim(a,b, semData=hsGO, measure="Wang", combine="BMA")
    }
    print(paste("ith Iteration: ",i))
  }
  
  </code></pre>
  
  <p>Here I wish to execute the mgoSim function using apply family of function for computation speed up as using 9076 x 9076 nested for loop, I am not getting result.</p>
  
  <p>Thanks in advance...</p>