title: define column names as combination of a repeated string and a vector in R
body: <p>I want to name the columns of a matrix by using a string and a vector of length of the rows. As an example:</p>
  
  <pre><code> k&lt;-c(5:15)
   xMin = 3
   xMax = 15
   x&lt;-c(xMin:xMax)
   M&lt;-matrix(, nrow = length(x), ncol = length(k))
  </code></pre>
  
  <p>Ideally, I would like to name the matrix columns using a string and the vector k, where the column name of the i'th column is the same as the item at the i'th position of the vector k.</p>
  
  <p>So, I would like it to look like is this:</p>
  
  <pre><code>      S5 S6 S7 S8 S9 S10 S11 S12 S13 S14 S15
   [1,] NA NA NA NA NA NA NA NA NA NA NA
   [2,] NA NA NA NA NA NA NA NA NA NA NA
   [3,] NA NA NA NA NA NA NA NA NA NA NA
   [4,] NA NA NA NA NA NA NA NA NA NA NA
   [5,] NA NA NA NA NA NA NA NA NA NA NA
   [6,] NA NA NA NA NA NA NA NA NA NA NA
   [7,] NA NA NA NA NA NA NA NA NA NA NA
   [8,] NA NA NA NA NA NA NA NA NA NA NA
   [9,] NA NA NA NA NA NA NA NA NA NA NA
  [10,] NA NA NA NA NA NA NA NA NA NA NA
  [11,] NA NA NA NA NA NA NA NA NA NA NA
  [12,] NA NA NA NA NA NA NA NA NA NA NA
  [13,] NA NA NA NA NA NA NA NA NA NA NA
  </code></pre>
  
  <p><em>where the string would be "S"</em>.
  Couriously, what didn't work was: </p>
  
  <pre><code>N=NULL
  N&lt;- as.vector(N)
  m=1
  for (m in length(k))
  {
  N[m]&lt;-paste0("s_",k[m])
  }
  N
  </code></pre>
  
  <p>=> The output was a vector full of NA's!
  Although, <strong>when I iterated 'm' by hand, it worked</strong> (WHY is it not working in the loop?)! </p>
  
  <p>Whatever, what I wanted to get, was of course: </p>
  
  <pre><code>&gt; N
   [1] "s_5"  "s_6"  "s_7"  "s_8"  "s_9"  "s_10" "s_11" "s_12"
   [9] "s_13" "s_14" "s_15"
  </code></pre>
  
  <p>which i could easily use for: </p>
  
  <pre><code>colnames(M)&lt;-N
  </code></pre>
  
  <p>I would of course want to use the same procedure for naming the rows.</p>