[R] group mean, minus each row's value

Casey Klofstad klofstad at gmail.com
Tue Nov 13 16:45:14 CET 2007


I used the following to assign each row the group average, where w is
the new group average variable, x is the variabale to be averaged, and
g is the nominal group indicator:

w <- ave(x,g)

Now I want to calculate the group average, but WITHOUT each row's
value of x. Is there an easy way to do this? I'm sure I'm missing
something obvious here, but for the life of me I can't figure it out.

Thanks!
-- 
Casey A. Klofstad
University of Miami
Department of Political Science
Coral Gables, FL

klofstad at gmail.com
http://moya.bus.miami.edu/~cklofstad



More information about the R-help mailing list