[R] Question about functionality of sum()

From: Vince S. Buffalo <vsbuffalo_at_ucdavis.edu>
Date: Tue 23 Jan 2007 - 19:12:52 GMT

R community,

My question is a bit complex to explain (and consequently difficult to search for in the archives). I will illustrate it with a simplified example.

If I have an array of sample sizes for various factor levels, of all different sizes (due to missing data), and another array of those same factor levels' means, and I would like to sum the squares and weight them with their corresponding sample size as such:

ss <- sum( n*(yi.bar - y..bar)^2)

[note that y..bar is not an array]

Will R parse the array n at the same rate as it is yi.bar (an equally long array of the means of those n samples)? Note that I am more sure of using something like:
x <- c(data...)
ss <- sum(length(na.exclude(x))*(mean(na.exclude(x)) - y..bar)^2)

But alas, there are cases when only the means and the sample sizes are supplied, but not the actual data. I would also like to stray away from using built-in functions (weighted.mean perhaps?) do gain an understanding of how this would be done.

Thank you!

"The greatest challenge to any thinker is stating the problem in a way
that will allow a solution."
-Bertrand Russell

R-help@stat.math.ethz.ch mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Wed Jan 24 06:18:50 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 23 Jan 2007 - 19:31:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.