How to simplify nested conditional for loop in R? I have this for loop for creating a list of variables:

vars &lt;- c( 'beta.o', 'sd.y') 
for (x in c('ghs', 'site', 'trt')) {
  if(model.parms[[x]] == 1) {
    data &lt;- data[, which(names(data) != x)]
  } else {
    data &lt;- data
    if(x!='ghs') {
      vars &lt;- c(vars, paste('sd.', x, sep = ''))
    }
    m &lt;- min(model.parms[[x]], 5)
    for (i in 1:m) {
      if(i == 1 &amp;&amp; x == 'site') {
        vars &lt;- c(vars, 'beta.site[1]')
      }
      if (i &gt; 1) {
        vars &lt;- c(vars, paste('beta.', x, '[', i, ']', sep=''))
      }
    }
  }
}


It has been bothering me terribly, and I have failed the last two times I have tried to replace it, although conceptually it should be able to be written in a few lines. Any advice?
This bit:

for (i in 1:m) {
  if(i == 1 &amp;&amp; x == 'site') {
    vars &lt;- c(vars, 'beta.site[1]')
  }
  if (i &gt; 1) {
    vars &lt;- c(vars, paste('beta.', x, '[', i, ']', sep=''))
  }
}


Says handle the first pass differently from all the others.  So I would replace it with this:

if (x == 'site') {
  vars &lt;- c(vars, 'beta.site[1]')
}
for (i in 2:m) {
  vars &lt;- c(vars, paste('beta.', x, '[', i, ']', sep=''))
}