title: I want to transform a forward star representation to incidence matrix
body: <p>I have a forward star representation and i want to convert to to incidence matrix i wrote the code but it gave me wrong answer </p>
  
  <pre><code>FS &lt;- data.frame(
      archsNo = c(1:12),
      snode = c(1,1,2,2,3,3,4,4,5,5,6,8),
      enode = c(2,4,4,5,2,5,6,7,7,8,7,7)) 
  print(FS)
  </code></pre>
  
  <pre><code>   archsNo snode enode
  1        1     1     2
  2        2     1     4
  3        3     2     4
  4        4     2     5
  5        5     3     2
  6        6     3     5
  7        7     4     6
  8        8     4     7
  9        9     5     7
  10      10     5     8
  11      11     6     7
  12      12     8     7
  
  </code></pre>
  
  <p>This what i have tried :</p>
  
  <pre><code>n = 8 #number of nodes 
  m = 12 #number of archs
  incidence &lt;- matrix(0L,nrow=n, ncol=m)
  for(row in 1:n)
  {
    for(col in 1:m)
    {
     incidence[row][col] = ifelse(row == snode[col],1,ifelse(row == enode[col],-1,0)) 
     row 
     snode[col]
     enode[col]
  
    }
  }
  incidence
  </code></pre>
  
  <p>This is the result :</p>
  
  <pre><code>[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
  [1,]    1    0    0    0    0    0    0    0    0     0     0     0
  [2,]   -1    0    0    0    0    0    0    0    0     0     0     0
  [3,]    0    0    0    0    0    0    0    0    0     0     0     0
  [4,]    0    0    0    0    0    0    0    0    0     0     0     0
  [5,]    0    0    0    0    0    0    0    0    0     0     0     0
  [6,]    0    0    0    0    0    0    0    0    0     0     0     0
  [7,]    0    0    0    0    0    0    0    0    0     0     0     0
  [8,]    0    0    0    0    0    0    0    0    0     0     0     0
  
  </code></pre>
  
  <p>for each cell if the node in the row is the starting node then it should contain 1 if end node then the cell should have -1 and else then 0 but this didn't happen</p>