title: Repeat each element in a string a certain number of times
body: <p>I'm using the <code>rep()</code> function to repeat each element in a string a number of times. Each character I have contains information for a state, and I need the first three elements of the character vector repeated three times, and the fourth element repeated five times.</p>
  
  <p>So lets say I have the following character vectors.</p>
  
  <pre><code>al &lt;- c("AlabamaCity", "AlabamaCityST", "AlabamaCityState", "AlabamaZipCode") 
  ak &lt;- c("AlaskaCity", "AlaskaCityST", "AlaskaCityState", "AlaskaZipCode")
  az &lt;- c("ArizonaCity", "ArizonaCityST", "ArizonaCityState", "ArizonaZipCode")
  ar &lt;- c("ArkansasCity", "ArkansasCityST", "ArkansasCityState", "ArkansasZipCode")
  </code></pre>
  
  <p>I want to end up having the following output.</p>
  
  <pre><code>AlabamaCity
  AlabamaCity
  AlabamaCity
  AlabamaCityST
  AlabamaCityST
  AlabamaCityST
  AlabamaCityState
  AlabamaCityState
  AlabamaCityState
  AlabamaZipCode
  AlabamaZipCode
  AlabamaZipCode
  AlabamaZipCode
  AlabamaZipCode
  AlabamaZipCode
  ...
  </code></pre>
  
  <p>I was able to get the desired output with the following command, but it's a little inconvenient when I'm running through all fifty states. Plus, I might have another column with 237 cities in Alabama, and I'll inevitably run into problems matching up the names in the first column with the values in the second column.</p>
  
  <pre><code>   dat = data.frame(name=c(rep(al[1:3],each=3), rep(al[4],each=6), 
                  rep(ak[1:3],each=3), rep(ak[4],each=6)))
     dat
  
  
     dat2 = data.frame(name=c(rep(al[1:3],each=3), rep(al[4],each=6), 
                  rep(ak[1:3],each=3), rep(ak[4],each=6)),
                  city=c(rep("x",each=15), rep("y",each=15)))
     dat2
  </code></pre>
  
  <p>Of course, in real life, the 'x' and 'y' won't be single values.</p>
  
  <p>So my question concerns if there is a more efficient way of performing this task. And closely related to the question, when does it become important to ditch procedural programming in favor of OOP in R. (not a programmer, so the second part may be a really stupid question) More importantly, is this a task where I should look for a oop related solution.</p>