title: How do I implement an if statement using a vector in a nicely documented manner?
body: <p>I have the following function</p>
  <pre><code>FEType &lt;- function(NoGears  ){
      ret=&quot;Low&quot;
      if ((NoGears == 1)   ) {ret =&quot;Med&quot;}
      return(ret)
  }
  </code></pre>
  <p>and I call it using</p>
  <pre><code>df &lt;- as.data.frame.matrix(trainingdata) 
  #No.Gears is an integer
  df$FEType = FEType( df$No.Gears  )
  </code></pre>
  <p>I get</p>
  <blockquote>
  <p>Warning message in if ((NoGears == 1)) {: &quot;the condition has length &gt;
  1 and only the first element will be used&quot;</p>
  </blockquote>
  <p>According to <a href="https://stackoverflow.com/questions/23316161/the-condition-has-length-1-and-only-the-first-element-will-be-used">this question</a> I need to use a vector
  But I am not seeing how to send a vector to my function.</p>
  <p>Update</p>
  <p>I was able to do the following;</p>
  <pre><code>FEType &lt;- function(v  ){
      ret=&quot;Low&quot;
      if ((v[1] == 1)   ) {ret =&quot;Med&quot;}
      return(ret)
  }
  </code></pre>
  <p>and call it via</p>
  <pre><code>df$FEType = FEType( c(df$No.Gears)  
  </code></pre>
  <p>The code is less than satisfying to read.
  How do I do this in a more readable manner?</p>
  <p>[Update]</p>
  <p>One answer is to use a names vector</p>
  <pre><code>FEType &lt;- function(v ,n  ){
     
      ret=&quot;Low&quot;
      names(v ) &lt;-n
      if ((v[&quot;NoGears&quot;] == 1)   ) {ret =&quot;Med&quot;}
      return(ret)
  }
  </code></pre>
  <p>I have asked <a href="https://stackoverflow.com/questions/64745104/how-do-i-write-a-user-defined-function-in-r">here</a> to give context to my problem.</p>