title: R create edge list
body: <p>New to the Stack Overflow, even though I've been checking what you guys post and answer for quite some time (just didn't have the time to join up while working on my Master's).</p>
  
  <p>TL;DR: I used the script presented here to process a dataset structured like the one below to get edges for a network. It worked but took way too long to process (24h for 2k rows). Any tip to a beginner R user on making it faster?</p>
  
  <p>In my last research project I ended up with a data.frame much like:</p>
  
  <pre><code>ID | Trait 1 | Trait 2 | Trait 3 | Trait 4 |  Trait 5
  01 |  TRUE   |   TRUE  |  Photo  |   City  |  Portrait
  02 |  FALSE  |   TRUE  |  Draw   |  Child  |  Portrait
  03 |  TRUE   |  FALSE  |  Photo  |   Misc  |  Landscape
  .
  .
  .
  </code></pre>
  
  <p>And this went on for some 2k rows. The intent was to build a network where each ID is a node, and the sum of common traits between 2 IDs would make up a weighted edge, i.e. ID 01 would have a weight 2 edge to both ID 2 and 3, while ID 2 would not have an edge to ID 3.</p>
  
  <p>To work this out I used the following script that runs through each row comparing each column value to add weight (each match = +1), ignoring rows already compared (being an undirected network, it was unnecessary to match both ways):</p>
  
  <p>Key: Source = ID to compare to; Target = ID being compared; Weight = Sum of matching cells/traits.</p>
  
  <pre><code>findEdges &lt;- function(){
      input &lt;- read.csv("nodes.csv",header=TRUE,stringsAsFactors=FALSE,sep=";")
      edges &lt;- read.csv("edges.csv",header=TRUE,stringsAsFactor=FALSE,skip=1,colClasses=c("integer","integer","integer"),col.names=c("Source","Target","Weight"))    
      for(i in 1:nrow(input)){ #row to be compared: Source
          for(j in 1:nrow(entrada)){ #rows that will compare to: Target
              weight &lt;- 0
              if( i &gt;= j ){
              } else {
                  for(k in 1:ncol(input)){ #column by column comparison
                      col &lt;- k
                      if(input[i,k] == input[j,k]){ #edge weight modifier
                          weight &lt;- weight+1
                          }
                  }
                  print(c("source= ",i,"target= ",j,"weight= ",weight)) #visual feedback of running script
                  newRow &lt;- data.frame(Source=i,Target=j,Weight=weight) #create row for compared pair
                  edges &lt;- rbind(edges,newRow) # add edge row to data frame
              }
          }
      }
      write.csv(edges,"edges.csv") #write data frame to csv file
  }
  findEdges()
  </code></pre>
  
  <p>which worked just fine and gave me the weighted edgelist I needed. Each row of the edgelist would be presentes as:</p>
  
  <pre><code>Source | Target | Weight
    01   |   02   |   2
    01   |   03   |   2
  </code></pre>
  
  <p>and so on...</p>
  
  <p>However, this script took almost 24h to process the entire dataset (2k rows, 5 columns except ID), and while that was not an issue before, I think it would be nice to check for some tips on a better/faster way to achieve the same results.</p>