title: Does an expected value command exist in R
body: <p>I'm sure there must be a straight forward command for this, but I've searched and can't find one. How do I get the expected value from a vector?</p>
  
  <p>Here are the values</p>
  
  <pre><code>y &lt;- c(0.05, 0.01, -0.1)
  </code></pre>
  
  <p>And their probabilities</p>
  
  <pre><code>p &lt;- c(0.2, 0.7, 0.1)
  </code></pre>
  
  <p>I can get <code>E(Y)</code> by doing</p>
  
  <pre><code>sum(y*p)
  </code></pre>
  
  <p>But I think there is probably a command for it right, I just can't find it. Thanks!</p>