Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>@KennyTM got it. @David, you should avoid <code>options(digits = 1)</code> since it will affect all of your calculations (it will suppress decimals in each output afterwards). So use <code>round()</code> function after applying the <code>weighted.mean()</code>. Something like this: </p> <pre><code>\Sexpr{round(p.mean(x))} </code></pre> <p>And <strong>do not</strong> use <code>print()</code>, but <code>return()</code>. Here's why:</p> <pre><code>&gt; set.seed(1234) &gt; x &lt;- rnorm(100) &gt; foo &lt;- function(x) { res &lt;- mean(x) + 5 print(res) } &gt; foo(x) [1] 5 &gt; foo(x) + 10 [1] 5 [1] 15 </code></pre> <p>Use <code>return()</code> or just type the resulting variable in the last line:</p> <pre><code>&gt; bar &lt;- function(x) { res &lt;- mean(x) + 5 return(res) } &gt; bar(x) + 10 [1] 15 </code></pre> <p>So, rewrite your function, and be sure to use <code>as.character()</code>... you have all the bits, now just put it all together.</p> <p>P.S.</p> <p>I'm not sure how you function works... I've never used weighed mean in my analysis. The bit that's puzzling me the most is <code>weight=weight</code>. Wouldn't it be nicer to put one more argument in function? Frankly, I'm still amazed by the fact that your function is giving you right result... probably because you have <code>weight</code> variable defined prior to function definition. <strong>[EDIT]</strong> You <strong>will not</strong> get the weighted mean with your function if you don't have <code>weight</code> function predefined, but "regular" mean!</p> <p>I hope this one helped you!</p> <p>Kind regards, Aleksandar</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload