title: R substr function on multiple columns
body: <p>I have 3 columns. First column has unique ID, second and third columns have string data and some NA data. 
  I need to extract info from column 2 and put it in separate columns and do the same thing for column 3. I am building a function as follows, using for loops. I need to split the columns after the third letter. [For example in the V1 column below, I need to break AAAbbb as AAA and bbb and put them in separate columns. I know I can use substr to do this. I am new to R, please help. </p>
  
  <hr>
  
  <p>UID    *         V1     *  V2  *</p>
  
  <hr>
  
  <p>Z001NL *    AAAbbb  * IADSFO *</p>
  
  <hr>
  
  <p>Z001NP *    IADSFO  * NA *</p>
  
  <hr>
  
  <p>Z0024G *    SFOHNL  * NLSFO0 *</p>
  
  <hr>
  
  <p>Here's my code.</p>
  
  <pre><code>test=read.csv("c:/some/path/in/windows/test.csv", header=TRUE)
  
  substring_it = function(test)
  {
  for(i in 1:3){
  for(j in 2:3){
  answer = transform(test, code 1 = substr((test[[j,i]]), 1, 3), code2 = substr((test[j,i]), 4, 6))
  
  }
  }
  return(answer)
  </code></pre>
  
  <p>}</p>
  
  <pre><code>hello = substring_it(test)
  </code></pre>
  
  <p>test will be my data frame that I will read in.</p>
  
  <p>I need this as my output</p>
  
  <hr>
  
  <p>UID    *   V1.1     * V1.2    * V2.1  * V2.2</p>
  
  <hr>
  
  <p>Z001NL *  AAA       * bbb     * IAD   * SFO</p>
  
  <hr>
  
  <p>Z001NP *  IAD       * SFO     * NA    * NA</p>
  
  <hr>
  
  <p>Z0024G *  SFO       * HNL     * NLS   * SFO</p>
  
  <hr>