title: Computation with different combinations of parameters using for loop
body: <p>I am trying to implement a for loop in R to fill a <code>df</code> with some combinations of learning rates and decays used in machine learning. The ideia is to try several learning rates and decays, calculate error metrics of these combinations and save in a dataset. So I could point out which combination is better.</p>
  <p>Below is the code and my result. I don't understand why I get this result.</p>
  <pre><code>learning_rate = c(0.01, 0.02) 
  decay = c(0, 1e-1) 
  
  combinations = length(learning_rate) * length(decay)
  
  df &lt;- data.frame(Combination=character(combinations),
                   lr=double(combinations), 
                   decay=double(combinations), 
                   result=character(combinations),
                   stringsAsFactors=FALSE) 
  
  for (i in 1:combinations) {
    for (lr in learning_rate) {
      for (dc in decay) {
         df[i, 1] = i
         df[i, 2] = lr
         df[i, 3] = dc 
         df[i, 4] = 10*lr + dc*4 # Here I'd do some machine learning. Just put this is easy equation as example
      }
    }
  }
  </code></pre>
  <p>The result I get. It seems that only the combination loop worked well. What I did wrong?</p>
  <pre><code> Combination   lr decay  result
             1 0.02   0.1   0.6
             2 0.02   0.1   0.6
             3 0.02   0.1   0.6
             4 0.02   0.1   0.6
  </code></pre>
  <p>I expected this result</p>
  <pre><code> Combination   lr decay   result
             1 0.01   0       0.1
             2 0.01   1e-1    0.5
             3 0.02   0       0.2
             4 0.02   1e-1    0.6
  </code></pre>