title: Recursive Index Failed
body: <p>This is my sample dataset. </p>
  
  <pre><code>     Id     longt    latit.   Count  V1  V2  V3  V4  V5  V6  V7
      19969   86.3603 23.8024     6    9   10  16  17  22  23  0
      19969   86.3602 23.8033     5    10  16  17  22  23  0   0
  </code></pre>
  
  <p>I want to merge the two row if any point is same in any other row. 
  V1, V2... represents indexes of a point which are in 100m radius to that of current point. Again and again, I am encountering with the error at row no. 6148 : </p>
  
  <pre><code>Error in `*tmp*`[[j]] : recursive indexing failed at level 2
  </code></pre>
  
  <p>Let me know if you need any more information!! 
  Here is the code I have used.</p>
  
  <pre><code>book &lt;- data.frame(book)
  book &lt;- as.data.frame.matrix(book)
  temp &lt;- data.matrix(book)
  
  S &lt;- 0
  k &lt;- 102
  for (i in 1:(nrow(book) - 1))
  {
    if (book[i, 6] &lt; 3) {
      book[i, 1] &lt;- 0
      next
    }
    if (book[i, 1] == book[i + 1, 1]) {
      for (j in (i + 1):nrow(book))
      {
        if (book[i, 1] != book[j, 1] &amp; book[j, 1] != "0") {
          break
        }
  
        for (q in 7:(6 + book[i, 6]))
        {
          t &lt;- (book[i, q])
          print(i)
          print(q)
          print((book[i, q]))
          if (distm(cbind(book[t, 3], book[t, 2]),
      cbind(book[j, 3], book[j, 2]), fun = distHaversine) &lt; 100) {
            S &lt;- book[i, 6] + book[j, 6]
            X &lt;- book[i, 6]
            Z &lt;- book[j, 6]
            if (S - k &gt; 0) {
              for (m in 1:(S - k))
              {
                book &lt;- data.frame(book)
                book &lt;- as.data.frame.matrix(book)
                B &lt;- matrix(0, nrow(book), 1)
                book &lt;- cbind(book, B)
                k &lt;- S
              }
            }
            book[i, 7:(6 + length(unique(c(
              temp[i, 7:(6 + temp[i, 6])], temp[j, 7:(6 + temp[j, 6])]
            ))))] &lt;-
              unique(c(temp[i, 7:(6 + temp[i, 6])], temp[j, 7:(6 + temp[j, 6])]))
  
            # if(Z!=0)
            # { for(p in 0:(Z-1) )
            # { book[i,(7+X+p)] &lt;- book[j,(7+p)] }
  
            #  }
            book[i, 6] &lt;-
              length(unique(c(temp[i, 7:(6 + temp[i, 6])], temp[j, 7:(6 + temp[j, 6])])))
  
            book[j, 1] &lt;- 0
            break
          }
        }
        book[is.na(book)] &lt;- 0
      }
    }
    for (f in 8:(6 + S))
    {
      book[book[i, f], 1] &lt;- 0
    }
  }
  </code></pre>
  
  <p>The data set where I got the error :</p>
  
  <pre><code>23918   86.7266 23.8197 31-03-16 4:54-- 31-03-16 5:03   0   0   0   0   0   0   0   0   0   0   0   0
  23924   86.3249 23.809  25-03-16 12:23--    25-03-16 12:31  8   6140    6141    6147    6154    6155    6156    6168    6174    0   0   0
  23924   86.3254 23.809  25-03-16 12:31--    25-03-16 12:39  10  6141    6147    6148    6155    6156    6157    6162    6168    6174    6183    0
  23924   86.3266 23.8089 25-03-16 12:42--    25-03-16 13:17  9   6142    6148    6149    6157    6158    6162    6175    6183    6184    0   0
  23924   86.3282 23.8034 25-03-16 13:22--    25-03-16 13:32  6   6143    6159    6169    6176    6185    6186    0   0   0   0   0
  23924   86.3326 23.7991 25-03-16 13:32--    25-03-16 14:04  5   6144    6150    6160    6170    6177    0   0   0   0   0   0
  23924   86.5447 23.8214 25-03-16 14:51--    25-03-16 15:14  1   6145    0   0   0   0   0   0   0   0   0   0
  23924   86.6195 23.801  25-03-16 15:25--    25-03-16 15:32  7   6146    6151    6164    6171    6178    6179    6187    0   0   0   0
  23924   86.3254 23.809  25-03-16 20:27--    25-03-16 20:33  9   6147    6148    6155    6156    6157    6162    6168    6174    6183    0   0
  23924   86.326  23.8091 25-03-16 20:33--    25-03-16 20:52  11  6148    6149    6156    6157    6158    6162    6168    6174    6175    6183    6184
  23924   86.3264 23.8088 25-03-16 20:52--    25-03-16 21:06  8   6149    6157    6158    6162    6168    6175    6183    6184    0   0   0
  23924   86.3322 23.7988 25-03-16 21:18--    25-03-16 22:16  4   6150    6160    6170    6177    0   0   0   0   0   0   0
  23924   86.6195 23.801  25-03-16 23:11--    25-03-16 23:26  6   6151    6164    6171    6178    6179    6187    0   0   0   0   0
  23924   86.6878 23.79   25-03-16 23:35--    26-03-16 0:13   4   6152    6172    6180    6191    0   0   0   0   0   0   0
  23924   86.7264 23.8197 26-03-16 0:39-- 26-03-16 0:46   7   6153    6165    6173    6181    6182    6188    6192    0   0   0   0
  23924   86.3241 23.8093 26-03-16 12:58--    26-03-16 13:53  2   6154    6155    0   0   0   0   0   0   0   0   0
  </code></pre>