title: r error recursive indexing failed at level 2 matrix
body: <p>Rows of a Matrix book store the latitude, longitude at column 2 and 3 and column 6 to n stores the indices of the points which are within 600 m to the ith one. In the below code, I am trying to check if any points in ith row is within a range to the jth point. If so, then I am appending the indices of both the rows. But while doing so, I am getting an error <code>Error in *tmp*[[j]] : recursive indexing failed at level 2</code>
  This is the data set </p>
  
  <pre><code>   vehicle_id  longt  latit  date   B B B B B B B B B B B B B B B
  1    19967   86.2885 23.8210   27   3 1 2 6 0 0 0 0 0 0 0 0 0 0 0
  2    19967   86.2891 23.8200   27   2 2 6 0 0 0 0 0 0 0 0 0 0 0 0
  3    19967   86.5343 23.8254   27   1 3 0 0 0 0 0 0 0 0 0 0 0 0 0
  4    19967   86.7273 23.8200   27   1 4 0 0 0 0 0 0 0 0 0 0 0 0 0
  5    19967   86.1362 23.7538   28   1 5 0 0 0 0 0 0 0 0 0 0 0 0 0
  6    19967   86.2839 23.8212   28   1 6 0 0 0 0 0 0 0 0 0 0 0 0 0
  
    B B B B B B B B B B B B B
  1 0 0 0 0 0 0 0 0 0 0 0 0 0
  2 0 0 0 0 0 0 0 0 0 0 0 0 0
  3 0 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 0
  5 0 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 0
  </code></pre>
  
  <p>I wanted to know why I am getting this errror and how could I resolve it.???/</p>
  
  <pre><code>S=0
  for(i in 1:(nrow(book)-1))
  {        
  
    if( book[i, 1] != book[i+1,1]  )
    {
      next
    }
  
  
  
  
  
   for(j in i:nrow(book))
    {  
  
  if(  book[i,1]!=book[j,1])
  {    
    break           }
  
  
  if(  book[i,1]==book[j,1] &amp;  (book[i,5] &gt; 2 ))
       {  for( k in 7:(5+book[i,5]))
  
  
  
    if(distm (c(book[book[i,k],3], book[book[i,k],2]), c(book[j,3], book[j,2]), fun = distHaversine) &lt; 600)               
    {     S=book[i,5]+book[j,5]
      if (S-k &gt; 0)
      {   B&lt;- matrix(0,nrow(book),(S-k))
      book &lt;- cbind(book,B)
      book[i,5]=book[i,5]+book[j,5]       
      } 
  
  
      book[i,(6+book[i,5]):((6+book[i,5])+book[j,5])] &lt;- book[j,(6:(5+book[j,5]))]
  
  
  
    }
  
  
  
  }
  
  
    }
   for( k in 7:(5+book[i,5]))
  
   {  if(i!=book[i,k])    
   {book[book[i,k],1]=0;
   }
   }
  
  
  
  
  
  
  }
  </code></pre>
  
  <p>`  </p>