title: r if else for loop with logical and boollean operators
body: <p>I'm trying to use an if else statement to create a new column of binary data in my data frame, but what I get is all zeros... </p>
  
  <p>command:</p>
  
  <pre><code>for(i in 1:nrow(asort)){
    if(asort$recip==0 &amp;&amp; asort$dist&lt;.74){
      asort$temp[i]&lt;-0
    } else{
      asort$temp[i]&lt;-1
    }
  }
  
  #temp ends up being all 0's
  </code></pre>
  
  <p>In addition, I would actually like to ask something along the lines of this:</p>
  
  <pre><code># if the data in the recip column = 0, and the distances is &lt; 0.74, OR if the #data is greater than 1.85 give me a zero, else 1
  
  for(i in 1:nrow(asort)){  
  if(asort$recip==0 &amp;&amp; asort$dist&lt;.74 || asort$dist&gt;1.85){
      asort$temp[i]&lt;-0
    } else{
      asort$temp[i]&lt;-1
    }
  }
  
  
   &gt; head(asort)
              coordinates CLASS_ID Flight   UFID      dist nnid  nnid2 observed recip temp
  157 (285293.3, 4426017)        0    F4_ F4_156 0.3857936  158 F4_157        0     0    0
  158 (285293.2, 4426017)        0    F4_ F4_157 0.3857936  157 F4_156        0     0    0
  259   (285255, 4426014)        0    F4_ F4_258 0.5226039  261 F4_260        1     0    0
  261   (285255, 4426014)        0    F4_ F4_260 0.5226039  259 F4_258        1     0    0
  402 (285275.3, 4426004)        0    F4_ F4_401 0.5598427  403 F4_402        1     0    0
  403 (285275.6, 4426004)        0    F4_ F4_402 0.5598427  402 F4_401        1     0    0
  </code></pre>