title: Interpreting "condition has length > 1" warning from `if` function
body: <p>I have an array:</p>
  
  <pre><code>a &lt;- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
  </code></pre>
  
  <p>and would like to implement the following function:</p>
  
  <pre><code>w&lt;-function(a){
    if (a&gt;0){
      a/sum(a)
    }
    else 1
  }
  </code></pre>
  
  <p>This function would like to check whether there is any value in <code>a</code> larger than 0 and if yes then divide each element by the sum of the total.</p>
  
  <p>Otherwise it should just record 1.</p>
  
  <p>I get the following warning message: </p>
  
  <pre><code> Warning message:
   In if (a &gt; 0) { :
   the condition has length &gt; 1 and only the first element will be used
  </code></pre>
  
  <p>How can I correct the function?</p>