Skip to content

weighting means

5 messages · Tim Wilson, Kjetil Halvorsen, Frank E Harrell Jr +1 more

#
Hi everyone,

I've got a dataframe called 'faculty'. I want to do a weighted mean on
the column called 'Q8' weighted by the contents of column 'CETP'. In
addition, I need to operate on the result of splitting 'faculty'
according to the contents of a column 'FACULTY'. For example
$"1"
[1] 2.2

$"2"
[1] 1.888889

gives the mean of 'Q8' after splitting by 'FACULTY'. When I try this
with weighted.mean, it doesn't work because I don't know how to specify
the result of the split as the argument for weighted.mean. For example,
$"1"
[1] 2.2

$"2"
[1] 1.888889

gives the same results as above because I haven't specified the vector
to use for weighting. The following doesn't work at all for the obvious
reason that weighted.mean is not operating on the result of the split.
faculty$CETP))
Error in match.fun(FUN) : not function, character, or symbol:
"weighted.mean(faculty$Q8, faculty$CETP)"
Any ideas?

-Tim
#
What about:
1          2 
-0.0976302 -0.1457895 


Kjetil Halvorsen
Tim Wilson wrote:
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Wed, 21 Aug 2002 12:10:44 -0400
kjetil halvorsen <kjetilh at umsanet.edu.bo> wrote:

            
Also take a look at the many weighted stats functions in the Hmisc library.  Do 
library(Hmisc)
?wtd.mean

-Frank
#
Hello to all

Is there a way to get weighted means using summary.formula() from Hmisc?

For example, the following doesn't work:
Error in wtd.mean(y, weights = z$w) : dim<- length of dims do not match the length of object

Thanks for the replies,

Oscar Rueda



22/08/02 1:16:15, Frank E Harrell Jr <fharrell at virginia.edu> escribió:
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Thu, 22 Aug 2002 14:51:14 +0200
Oscar Rueda <orp at intras.es> wrote:

            
Not at present.  That would not be very hard to add to summary.formula and I will add that to my "to do" list.  -Frank