title: How to apply a function to each element of a vector in R
body: <p>Let's say I want to multiply each even element of a vector by 2 and each odd element of a vector by 3. Here is some code that can do this:</p>
  
  <pre><code>v &lt;- 0:10
  
  idx &lt;- v %% 2 == 0
  v[idx] &lt;- v[idx] * 2
  v[!idx] &lt;- v[!idx] * 3
  </code></pre>
  
  <p>This would get difficult if I had more than two cases. It seems like the apply family of functions never deals with vectors so I don't know a better way to do this problem. Maybe using an apply function would work if I made transformations on the data, but it seems like that shouldn't be something that I would need to do to solve this simple problem.</p>
  
  <p>Any ideas?</p>
  
  <p>Edit: Sorry for the confusion. I am not specifically interested in the "%%" operator. I wanted to put some concrete code in my question, but, based on the responses to the question, was too specific. I wanted to figure out how to apply some arbitrary function to each member of the list. This was not possible with apply() and I thought sapply() only worked with lists.</p>