title: Add character to element within a matrix in R
body: <p>I'm looking for a way to add a character to a sample of an element within a matrix. I create then sample a matrix containing a random distribution of the letters a - e, and what I'm hoping to do next is create a "speciation" event in which whatever element I sample, becomes a "new species". E.G. Sample of matrix is a "c", then I add a "2" to it, so it becomes "c2".  </p>
  
  <p>The base code I run this under right now is:  </p>
  
  <pre><code>##Create Species Vector
  species.v&lt;-letters[1:5]
  species.v&lt;as.character(species.v)
  ##Check species Vector
  species.v
  
  
  #Matrix creation (Random)
  orig.neutral&lt;- matrix(sample(species.v,25,replace=TRUE),
                          nrow=5,
                          ncol=5)
  ##Check neutral.matrix
  orig.neutral
  
  
  ##Random Replacement
  orig.neutral[sample(length(orig.neutral),1)]&lt;-as.character(sample(orig.neutral,1))
  orig.neutral
  </code></pre>
  
  <p>What I would like to do is then swap the random replacement</p>
  
  <blockquote>
    <p>orig.neutral[sample(length(orig.neutral),1)]&lt;-as.character(sample(orig.neutral,1)</p>
  </blockquote>
  
  <p>for a way to add a 2 to whatever the contents of the sample is.  </p>
  
  <p>In an ideal world I'd also be able to add further speciation if there is already a number within that cell (i.e. if it is already "b2" I could make it "b3" but I think I could do that with if functions anyway, just need to code to actually add the 2 in the first place. (Though having thought about it more that'd only end up with b23... which is not what I want at all!)</p>
  
  <p>Any help would be appreciated</p>
  
  <p>many thanks</p>
  
  <p>Edit:  </p>
  
  <p>Using paste as recommended by @sam81, I have added the line:  </p>
  
  <pre><code>neutral.v0&lt;-orig.neutral ##keep original to compare
  
  neutral.v0[sample(length(neutral.v0),1)] = paste("2", sep=" ")
  </code></pre>
  
  <p>which only replaces whatever the sample is with 2, as opposed to adds 2 to whatever was in the sample. I tried paste((sample(length(neutral.v0),1)),"2",sep="") but that just returned numbers into the matrix (e.g. "19 2") which I assume was the position in matrix that was sampled.</p>