title: R - ifelse statement with two conditions
body: <p>I'm new to R and want to understand why &quot;ifelse&quot; fails in my case.</p>
  <p>I have a vector of longitudes and radii. If the lons are &lt; 0 then the code should do lons - (zrad/dxy), if lons are &gt;= 0 then lons + (zrad/dxy) should be calculated.</p>
  <p>Some example data:</p>
  <pre><code>lons &lt;- c(-80,4)
  zrad &lt;- c(747,576)
  dxy  &lt;- 222
  </code></pre>
  <pre><code>test &lt;- ifelse(lons &lt; 0 | lons &gt;= 0, lons - (zrad/dxy), lons + (zrad/dxy))
  View(test)
  </code></pre>
  <p>This gives me</p>
  <pre><code>1   -83.364865
  2   1.405405
  </code></pre>
  <p>However, lons - (zrad/dxy) is</p>
  <pre><code>-83.364865  1.405405 
  </code></pre>
  <p>and lons + (zrad/dxy) is</p>
  <pre><code>-76.635135  6.594595
  </code></pre>
  <p>But the right result should be</p>
  <pre><code>-83.364865 6.594595
  </code></pre>
  <p>Do I need to use a for-loop so that &quot;test&quot; includes the result from the first and second calculation?
  Or is there an easier way to differentiate the two cases(conditions)?</p>