I was trying to do this: (the following dataframe is just to show the idea)
a b c
[1,] 1 1 2
[2,] 1 3 5
[3,] 2 2 4
[4,] 2 1 5
in which 'a' is the factor that groups 'b' and 'c' into two categories. I want to get the weighted mean of a (b as the weight, or actually, b/Sum(b) as the weight). I couldn't find a function that operates more than one variables with the same factor.
In this example, i want to get two means:
group a=1: (1*2+3*5)/(2+5)=17/7
group a=2: (2*4+1*5)/(4+5)=13/9
I'm new to R so this is really hard for me to handle. Hope you guys could spare a few seconds to comment. Thanks very much!