title: How to apply same function to different sets of column in R?
body: <p>With the following data set and <code>time</code> variable as <code>time=c(1:10)</code></p>
  
  <pre><code>mydata
    beta_C1 1 beta_C1 2    beta_C1 3 beta_C2 1 beta_C2 2     beta_C2 3
  1  5.388135 0.2036038 -0.006050338  5.488691 0.1778483 -0.0036647072
  2  5.536004 0.2374793 -0.009960762  5.768781 0.1463565 -0.0012642700
  3  5.798095 0.1798015 -0.004768584  6.059320 0.1127296  0.0006366231
  4  5.648306 0.2720582 -0.011654632  6.129815 0.1282014 -0.0015109727
  5  5.712576 0.2320445 -0.007225099  6.166659 0.1490687 -0.0042889325
  6  5.674026 0.2325392 -0.006198976  6.242121 0.1559551 -0.0064668515
  </code></pre>
  
  <p>I would like to create two matrix such as </p>
  
  <pre><code>new_mat1=outer(1:nrow(mydata), 1:length(time), function(x,y){
    mydata[x,1]+
      mydata[x,2]*time[y]+
      mydata[x,3]*time[y]^2
  })
  </code></pre>
  
  <p>and </p>
  
  <pre><code>new_mat2=outer(1:nrow(mydata), 1:length(time), function(x,y){
    mydata[x,4]+
      mydata[x,5]*time[y]+
      mydata[x,6]*time[y]^2
  })
  </code></pre>
  
  <p>The first matrix is created by taking the first three columns of <code>mydata</code> and the last three columns are used to create the second matrix. 
  Can I apply a function or for loop to create both matrices together? Any help is appreciated</p>