[R] calculating mean and s.d. from a two-column table

Peter Langfelder peter.langfelder at gmail.com
Mon Sep 27 18:43:07 CEST 2010


On Mon, Sep 27, 2010 at 9:34 AM, Jonas Josefsson
<jonas at runtimerecords.net> 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

You can use the following trick:

x = rep(age, no)

This repeats age[1] no[1]-times, age[2] no[2]-times, etc...

then use the usual mean and sd on x.

Peter



More information about the R-help mailing list