title: R: How to use ifelse statement for a vector of characters
body: <p>I am trying to solve a quiz using R, but my code does not work properly. I tried debugging, but it seems that the ifelse statement fails to work at certain numbers that seem pretty random.</p>
  
  <p>Here is the quiz: <a href="http://puzzles.nigelcoldwell.co.uk/six.htm" rel="nofollow">http://puzzles.nigelcoldwell.co.uk/six.htm</a></p>
  
  <pre><code>switches &lt;- rep("off", 100)
  for(i in 1:100){
    k &lt;- c(seq(i, 100, i))
    ifelse(switches[k] == "off", switches[k] &lt;- "on", switches[k] &lt;- "off")
  }
  </code></pre>
  
  <p>When I run this code, I get "on" for 14, 22, 26, 30, 34, etc in which I should have got "off." Is there a mistake in the way I applied ifelse statement to a vector with vectorized index?</p>