title: Use sapply or Vector?
body: <p>I'm new to R and I find it ambiguous whether I should use a vector as the argument to call a function or use sapply instead to give the variables in the vector to the function one by one. </p>
  
  <p>Isn't it the same thing? Why sapply exists if it's the same thing? Is there times when I should use one way or the other and how to know wich way to use? </p>
  
  <p>This question came to my mind because I was writing this</p>
  
  <pre><code>sapply(1:3, function(i) dnorm(i,0,1))
  </code></pre>
  
  <p>Then I accidentally discovered that I could do </p>
  
  <pre><code>dnorm(1:3,0,1)
  </code></pre>
  
  <p>How could I know it if I didn't discover it by accident (in order not to do the same mistake with other functions )?</p>
  
  <p>Discovering that I tried to change in the same way this code </p>
  
  <pre><code>kappa &lt;- c(1,2,3,4,5,6,7)
  
  sapply(kappa, function(t) 
    optimize(function(x) (t*x^22+5*x+6), c(-10,10))$minimum)
  </code></pre>
  
  <p>to this</p>
  
  <pre><code>kappa &lt;- c(1,2,3,4,5,6,7)
  
    optimize(function(x) (kappa*x^22+5*x+6), c(-10,10))$minimum
  </code></pre>
  
  <p>but it didn't work!</p>
  
  <p>Please I need a good explanation.</p>
  
  <p>Thank you</p>