[R] calculating mean and s.d. from a two-column table
ehlers at ucalgary.ca
Thu Sep 30 11:16:18 CEST 2010
On 2010-09-27 15:20, Joshua Wiley wrote:
> Peter's suggestion is more general, but for just the weighted mean,
> there is a built in function you can use (I do not know of any basic
> weighted standard deviation or variance functions).
> dat<- data.frame(age = 1:5, no = c(21, 31, 9, 12, 6))
> weighted.mean(x = dat$age, w = dat$no)
> Best regards,
Hmisc has wtd.mean() and wtd.var() as well as a few other
> 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.
>> 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?
>> R-help at r-project.org mailing list
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help