[R] calculating mean and s.d. from a two-column table
Jim Lemon
jim at bitwrit.com.au
Tue Sep 28 09:42:14 CEST 2010
On 09/28/2010 02:34 AM, Jonas Josefsson wrote:
> I have a two-column table as follows where age is in the 1st column and
> the number of individuals is in the 2nd.
>
> age;no
> 1;21
> 2;31
> 3;9
> 4;12
> 5;6
>
>
> Can I use mean() and sd() to calculate the mean and standard deviation
> from this or do I have to manually multiplicate 21*1+31*2 etc. / N?
>
Hi Jonas,
You can also use weighted.mean:
weighted.mean(age,no)
Jim
More information about the R-help
mailing list