title: R - create variables in a dataframe using other variables with a for loop
body: <p>Sorry if this is too simple a question but for the life of me cant sort this out.</p>
  
  <p>I have a data frame with a continuous variable and need to create multiple logical variables based on the value of the continuous variable.</p>
  
  <p>Hopefully the example below illustrates this:</p>
  
  <pre><code>x &lt;- as.integer(rnorm(n=1000, mean=10, sd=5))
  
  y &lt;- 1:1000
  
  df &lt;- data.frame(x,y)
  
  for i in 1:10 {
  
    df$[i] &lt;- ifelse (df$x&lt;[i],1,0)
  
  }
  </code></pre>
  
  <p>I suspect I am going wrong at the <code>df$[i]</code> expression...any solutions?</p>
  
  <p>Thanks in advance</p>