title: Logical comparison of two vectors with binary (0/1) result
body: <p>For an assignment I had to create a random vector theta, a vector p containing for each element of theta the associated probability, and another random vector u. No problems thus far, but I'm stuck with the next instruction which I report below:</p>
  
  <p>Generate a vector r1 that has a 1 in position i if pi ≥ ui and 0 if pi &lt; ui. The
  vector r1 is a Rasch item given the latent variable theta.</p>
  
  <pre><code>theta=rnorm(1000,0,1)
  p=(exp(theta-1))/(1+exp(theta-1))
  u=runif(1000,0,1)
  </code></pre>
  
  <p>I tried the following code, but it doesn't work.</p>
  
  <pre><code>r1&lt;-for(i in 1:1000){
  if(p[i]&lt;u[i]){
    return("0")
  } else {
    return("1")}
  }
  </code></pre>