title: In R, is it possible to use a pair, tuple or equivalent in a matrix?
body: <p>I am trying to create a matrix of coordinates(indexes) that I randomly pick one from using the sample function. I then use these to select a cell in another matrix. What is the best way to do this? The trouble is how to store these integers in the matrix so that they are easy to separate. Right now I have them stored as strings with a comma, that I then split. Someone suggested I use a pair, or a string, but I cannot seam to get these to work with a matrix. Thanks!</p>
  <p>EDIT:What i currently have looks like this (changed a little to make sense out of context):</p>
  <pre><code>
  probs &lt;- matrix(c(0,0,0.6,0,0,
                    0,0.7,1,0.7,0,
                    0.6,1,0,1,0.6,
                    0,0.7,1,0.7,0,
                    0,0,0.6,0,0),5,5)
    
  cordsMat &lt;- matrix(&quot;&quot;,5,5)
  
  for (x in 1:5){
    for (y in 1:5){
        
      cordsMat[x,y] = paste(x,y,sep=&quot;,&quot;)
        
    }
  }
  
  
  
  cords &lt;- sample(cordsMat,1,,probs)
  cordsVec &lt;- unlist(strsplit(cords,split = &quot;,&quot;))
  cordX &lt;- as.numeric(cordsVec[1])
  cordY &lt;- as.numeric(cordsVec[2])
  
  otherMat[cordX,cordY]
              
  </code></pre>
  <p>It sort of works but i would also be interested for a better way, as this will get repeated a lot.</p>