title: Missing value where TRUE/FALSE needed in min function
body: <p>Question 1. Write a function called <code>my_min()</code> that computes the minimum of a numeric vector without the min() function. Include a logical argument called na.rm that specifies whether to remove NAs.</p>
  
  <pre><code>my_min &lt;- function(x){
    for (i in 1:length(x)) {
        if (x[i] &lt; x[i+1]) {
          result &lt;- x[i]
        } else {
          result &lt;- x[i+1]
        }
    }
  result
  }
  
  my_min(1:10)
  </code></pre>
  
  <blockquote>
    <p>Error in if (x[i] &lt; x[i + 1]) { : missing value where TRUE/FALSE needed</p>
  </blockquote>
  
  <p>I don't know why there is a  missing value; can someone teach me how to do it with an <code>if</code> statement? (even if it does not need it, I just want to know the correct way to answer this question with an <code>if</code> statement). </p>