title: R Populate specific vectors in a matrix with names from an index
body: <p>I'm writing script to reformat data and I'm having trouble populating it with the right values/names.</p>
  
  <p>The data starts as:</p>
  
  <pre><code>data1=
  
      Date         conc1   conc2   conc3
      Control      XXXX    XXXX    XXXX
      Control      XXXX    XXXX    XXXX
      Control      XXXX    XXXX    XXXX
      Treatment1   XXXX    XXXX    XXXX
      Treatment1   XXXX    XXXX    XXXX
      Treatment1   XXXX    XXXX    XXXX
  </code></pre>
  
  <p>and needs to end up as </p>
  
  <pre><code>formatdata1=
  
      Treatment    conc    value
      Control      conc1   XXXX
      Control      conc1   XXXX
      Control      conc1   XXXX
      Control      conc2   XXXX
      Control      conc2   XXXX
      Control      conc2   XXXX
      Control      conc3   XXXX
      Control      conc3   XXXX
      Control      conc3   XXXX
      Treatment1   conc1   XXXX
      Treatment1   conc1   XXXX
      Treatment1   conc1   XXXX
      Treatment1   conc2   XXXX
      Treatment1   conc2   XXXX
      Treatment1   conc2   XXXX
      Treatment1   conc3   XXXX
      Treatment1   conc3   XXXX
      Treatment1   conc3   XXXX
  </code></pre>
  
  <p>Currently I've pre-allocated a matrix of the correct dimensions:</p>
  
  <pre><code>formatdata1&lt;-array(0,dim=c(nrow(data1[+1])*ncol(data1[-1])+1,3))
  </code></pre>
  
  <p>indexed unique Treatment names:</p>
  
  <pre><code>unik&lt;-!duplicated(data2[,1])
  ind&lt;-seq_along(data2[,1])[unik]
  Treatname&lt;-data.frame(data2[,1][unik]) #extracted the unique names
  </code></pre>
  
  <p>And filled the first row of the matrix with headings:</p>
  
  <pre><code>formatdata1[1,]=c("Treatment","Conc","Value")
  </code></pre>
  
  <p>So what I'd like to do now is fill the remainder of column 1 of <code>formatdata</code> with the correct number of treatment names, using <code>ind</code> and <code>Treatname</code>.</p>
  
  <p>What I have currently is a line that reads like this:</p>
  
  <pre><code>formatdata1[ind[1]+1:((ind[2]-1)*ncol(data2[-1])),1]&lt;-Treatname[1,1]
  </code></pre>
  
  <p>This does fill the correct number of cells (so i believe my indexing is right), however, instead of the treatment name i want (in this case <code>Control</code>) it is filled with just <code>1</code>.</p>
  
  <p>How do I get it to use the name instead of the number? I assume there's something I can add to <code>&lt;-Treatname[1,1]</code>?</p>