Tuesday, 15 September 2015

R ddply and weighted mean -


I tried to calculate an aggregation with the weighted mean (average viewing time per views) on a table called DFA_CMO I'm doing DFA_CMO has 5 dimensions, and the site from them.

Here's the code:

  ddply (DFA_CMO ,. (on site), short, wm = weighted.mean (DFA_CMO $ average viewing time, DFA_CMO $ scene ,, NA.rm = TRUE))   

but the result shows the same price for a disappointing, because each field:

  site wm 1 Advideum 21.17633 2 Bibisikcom 21.17633 3 Borsorama 21.17633 4 canal Plus 21.17633 5 CNN network 21.17633 6 Euronews FR 21.17633 7 Amntritimdooka 8 21.17633 21.17633 Elfdifdis 9 take Monde 21.17633 10 Les Echoes 1 11 21.17633 21.17633 Lopiniankf 12 TF 1 Ipim 2lkl7633 14 Waisje UK - IBM PE 21.17633   

It seems that everything that happens on average shown here, it should be different at each site. Any idea how to get the correct value

Do not DFA_CMO $ & lt; Var_name & gt; To call ddply simply pass the variable names themselves.

  ddply (DFA_CMO ,. (on site), short or, wm = weighted.mean (average visible time, visual ,, na.rm = TRUE))   

The reason for this is that by giving the name of the data frame, you are effectively taking the defined vectors into weighted mean function, that is, the value of all rows in your data frame. If you pass only the column names, then ddply will evaluate them in relation to those line subsets related to each group.

No comments:

Post a Comment