Hi,

I have 2 huge datasets - May and Jun - a miniscule sample of one is given
below. I am trying to do 2 things with these datasets. I need to verify if
the weighted average of variable A for a Reason in Jun is same/different
from the same for May. To do this I am first computing the weighted average
for each SubReason using a function I wrote. 

Where I need help is applying the function on both the datasets to arrive at
weighted averages for each SubReason. Then, I would like to know what the
best way would be, to compare the weighted average for a sub reason across 2
datasets to be able to state that there is a difference - t-test,ANOVA?
Would greatly appreciate any help!! The function I wrote for weighted
average computation is given below the dataset.

One of the datasets:

Reason  SubReason    A  N
A                  SR1        1115      29
B                  SR2        734       24
B                  SR2        1054      31
A                  Sr1                600       43
A                  SR3        1033      60
A                  Sr1                1163      30
B                  SR4        732       43
B                  SR4        988       70
A                  SR3        569       25
B                  SR4        1073      65

Output I require:
R       SR      WA_A                       N (Sum of N)
A       SR1        912.0098                  102
        SR3        896.5294118       85
B       SR2        914.3636364       55
        SR4        957.1966292       178
                (Weighted Average 
                of A for N weights)

# FUNCTION TO CALCULATE THE WEIGHTED AVERAGE FOR A WEIGHTED BY N       
WA<-function(A,N) {
         sp_A<-c(A %*% N)
         sum_N<-sum(N)
         WA<-sp_A/sum_N   
         return(WA)      
         }

Thanks in advance!
Raoul




-- 
View this message in context: 
http://r.789695.n4.nabble.com/Weighted-Average-application-on-Summary-Dataset-tp2253239p2253239.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to