title: for loop to change the value of arguments of a built in function
body: <p>I'm trying to write a for loop that use a built-in function, changing the value of one of its arguments at every run.</p>
  
  <p>The built-in function is qmatrix.mns from msm package (multi-stage-Markov models). It calculates transition rates amongst different stages. Its main arguments are: a multistage Markov model (msm.Full) and covariates (provided in a list). </p>
  
  <p>I wrote the following function (it worked):</p>
  
  <pre><code>transRate&lt;-function(grossTon,held, cpue){
    estim&lt;-data.frame(matrix(rep(0,21),7,3))  
    for(i in 1:3){  
      qMatrix&lt;-qmatrix.msm(msm.Full,  ci="normal", covariates=list(grossTon=grossTon,    held=held, cpue=cpue,period=i))
  
            estim[i]&lt;-qMatrix$estimates[c(5,2,10,7,13,14,15)]# extracts transition rates that I'm interested in
            rownames(estim)&lt;-c("q12","q21","q23","q32","q14","q24","q34")
            colnames(estim)&lt;-c("period 1", "period 2","period 3")
          }
  
            return(estim)                     
      }                    
  
      transRate(grossTon=10,held=10,cpue=0.5)
  </code></pre>
  
  <p>the result was:</p>
  
  <pre><code>    period1     period2     period3
  q12 0.011523315 0.01100657  0.01051299
  q21 0.006939337 0.00528312  0.004022193
  q23 0.161752987 0.079884    0.039451841
  q32 0.016379169 0.01661803  0.01686038
  q14 1.134517831 1.13026321  1.126024543
  q24 0.426243172 0.78585263  1.448854529
  q34 0.240552571 0.74682982  2.318639844
  </code></pre>
  
  <p>It was easy, because the covariate "period" has 3 possible values: 1, 2, 3, but the story was different when I tried with the covariate "grossTon", whose potential values are between 10 and 120. What I want to is that grossTon takes values 10, 20, 30, ...,120.</p>
  
  <p>Please have a look at what I did:</p>
  
  <pre><code>transRate&lt;-function(held, cpue, period){
  estim&lt;-data.frame(matrix(rep(0,84),7,12)) 
  grossT&lt;-c(10,20,30,40,50,60,70,80,90,100,110,120)
    for(i in grossT){  #I guess the problem is here
      qMatrix&lt;-qmatrix.msm(msm.Full,  ci="normal", covariates=list(grossTon=i, held=held, cpue=cpue,period=period))
      estim[i]&lt;-qMatrix$estimates[c(5,2,10,7,13,14,15)]
      rownames(estim)&lt;-c("q12","q21","q23","q32","q14","q24","q34")
      colnames(estim)&lt;-c("10","20","30","40","50","60","70","80","90","100","110","120")
  
     }
      return(estim)                     
  }                    
  
  transRate(held=10,cpue=0.5,period=1)
  </code></pre>
  
  <p>What I'm expecting is the following output:</p>
  
  <pre><code>    10  20  30  40  50  60  70  80  90  100 110 120
  q12                                             
  q21                                             
  q23                                             
  q32                                             
  q14                                             
  q24                                             
  q34 
  </code></pre>
  
  <p>Thanks a lot in advance.</p>