title: How to run the function multiple times in r
body: <p>I want to run the function Nobel 10 times and get a table of values of Percent_lnOR and  Percent_Rho, so that for every iteration I will get those two values. </p>
  
  <p>How to run the function multiple times(say, 10 times), and get a table of values for Percent_lnOR and  Percent_Rho ?</p>
  
  <pre><code>library(gtools)
  
  Nobel&lt;-function(n){
    p11hat&lt;-rep(0,n)
    p12hat&lt;-rep(0,n)
    p21hat&lt;-rep(0,n)
    p22hat&lt;-rep(0,n)
    Rho&lt;- rep(0,n)
    AsyVarRho&lt;-rep(0,n)
    OddsRatio&lt;-rep(0,n)
    lnOR&lt;-rep(0,n)
    AsyVarOR&lt;-rep(0,n)
    count_lnOR&lt;-rep(0,n)
    count_Rho&lt;-rep(0,n)
  
  
    for (i in 1:n) { 
      MB &lt;- rdirichlet(1, c(1,1,1,1))
      #print (MB)
      Sample&lt;-rmultinom(n, 100, prob= c(MB[1,1], MB[1,2], MB[1,3], MB[1,4]))
  
      p11hat &lt;- Sample[1,i]/100
      p12hat &lt;- Sample[2,i]/100
      p21hat &lt;- Sample[3,i]/100
      p22hat &lt;- Sample[4,i]/100
  
  
      p1p &lt;- p11hat + p12hat
      p2p &lt;- 1-p11hat-p12hat
      pp1 &lt;- p11hat+p21hat
      pp2 &lt;- 1-p11hat-p21hat
      Var1 &lt;- p11hat*(1-p11hat)
      Var2 &lt;- p12hat*(1-p12hat)
      Var3 &lt;- p21hat*(1-p21hat)
      Cov12 &lt;- -p11hat*p12hat
      Cov13 &lt;- -p11hat*p21hat
      Cov23 &lt;- -p12hat*p21hat
      U &lt;- sqrt(p1p*p2p*pp1*pp2)
      V &lt;- p11hat*p2p*pp2 - p12hat*p2p*pp1 - p21hat*p1p*pp2 + (1-p11hat-p12hat-p21hat)*p1p*pp1
  
      DUDx &lt;- (1-p1p-pp1)*(p1p+pp1-2*p1p*pp1)
      DUDy &lt;- pp1*(1-pp1)*(1-2*p1p)
      DUDz &lt;- p1p*(1-p1p)*(1-2*pp1)
      DVDx &lt;- 1-p1p-pp1
      DVDy &lt;- -pp1
      DVDz &lt;- -p1p
      DfDx &lt;- (1/sqrt(U))*DVDx - 0.5*U^(-1.5)*V*DUDx
      DfDy &lt;- (1/sqrt(U))*DVDy - 0.5*U^(-1.5)*V*DUDy
      DfDz &lt;- (1/sqrt(U))*DVDz - 0.5*U^(-1.5)*V*DUDz
      AsyVarRho &lt;- Var1*DfDx^2 + Var2*DfDy^2 + Var3*DfDz^2 + 2*Cov12*DfDx*DfDy +
        2*Cov13*DfDx*DfDz + 2*Cov23*DfDy*DfDz
  
      OddsRatio &lt;- p11hat*(1-p11hat-p12hat-p21hat)/(p12hat*p21hat)
      lnOR &lt;- log(OddsRatio)
  
      AsyVarOR &lt;- (1/p11hat + 1/p12hat + 1/p21hat + 1/(1 - p11hat - p12hat - p21hat))
      Rho &lt;- V/sqrt(U)
      z1&lt;-lnOR/sqrt(AsyVarOR/100)
      z2&lt;- Rho/ sqrt(AsyVarRho/100)
      count_lnOR&lt;-ifelse(abs(z1)&gt;1.96,1,0)
      count_Rho&lt;-ifelse(abs(z2)&gt;1.96,1,0)
  
    }
  
    df &lt;- data.frame(p11hat, p12hat, p21hat, Rho, AsyVarRho, OddsRatio,lnOR, AsyVarOR,count_lnOR,count_Rho )
    return(df)
  }
  
  Y&lt;-Nobel(10)
  Y
  
  C_lnOR&lt;-as.matrix(table( Y$count_lnOR))
  C_Rho&lt;-as.matrix(table( Y$count_Rho))
  Percent_lnOR&lt;- (C_lnOR[2]/ sum(C_lnOR[1], C_lnOR[2]))*100 
  Percent_Rho&lt;- (C_Rho[2]/ sum(C_Rho[1], C_Rho[2]))*100 
  </code></pre>