title: "non-numeric argument to binary operator" error in R
body: <p>I've been trying to run this function and the "non-numeric argument to binary operator" pops up. I've seen quite a few questions similar to mine, yet I still can't figure out what is the issue with my code. </p>
  
  <pre><code>TakeOneIndStep &lt;- function(Itl, N){     # Itl is a vector  
    foo &lt;- ListMaintenance(Itl, N)        # is a vector of same length as Itl. Displays the coordinates of coalesced walks. 
    incrm &lt;- sample(c(-1, 0, 1), size = length(Itl), replace =  T, prob = c(0.25, 0.5, 0.25))
    for (j in 1:length(Itl)){
      if(Itl[j] %in% foo){
       Itl[j] &lt;- (Itl[j] + incrm[j]) %% N
     }else{
       Itl[j] &lt;- "H"              # H is a "placeholder", just to indicate that that particular chain has coalesced and no longer is updated. 
     }
   }
    return(Itl)
  }
  </code></pre>
  
  <p>The error happens on the sixth line <code>Itl[j] &lt;- (Itl[j] + incrm[j]) %% N</code>.</p>
  
  <p>The code for the auxiliary functions: </p>
  
  <pre><code>ListMaintenance &lt;- function(Temp, N){    # Temp is a vector
    rez &lt;- CheckCoalescence(Temp)
    fubar &lt;- vector()
    for(i in 1:length(rez)){
      for(x in 0:(N-1)){if (x %in% rez[[i]]){fubar[x] &lt;- min(rez[[i]])}
      }
    } 
    return(fubar)                  # output is a vector. Coordinates with the same value have the index of the smallest occurrence.  
  }
  
  CheckCoalescence &lt;- function(Pts){
    mar &lt;- unname(split(seq_along(Pts), Pts))
    return(mar)
  }
  </code></pre>
  
  <p>On the big picture, I'm trying to simulate a random walk process with more than two different starting points. So the argument <code>Itl</code> would be the values of each walk at time (t-1), and this function will recursively update these values. </p>
  
  <p>For practical purpose, I tried to test the function with <code>A &lt;- c(0, 2, 3, 2, 6)</code> and <code>TakeOneIndStep(A, N = 9)</code> </p>
  
  <p>In this case, <code>A</code> is just an arbitrary vector. There's more code to simulate the walk, but I just presented the part that is causing the error. </p>