I am trying to make "basic group" - style weighted mean with some groups. Plaiders package from Hadley) worked well.
ddply (mydf, (period), mean) If I use the same approach with weighted then I get the following error 'X' and 'wa' should be the same length, which I do not understand because weighted. Mean part works out of DDPA.
weighted.man (mydf $ mycol, mydf $ myweight) # Just works fine ddply (mydf, (period), weighted.mean, mydf $ mycol, mydf $ myweight) # The error described at I have a custom The thought of writing the function was using Weighted.mean and then it is going to write something new from scratch with ddply or subtitle. In my case it will work a lot more than expected, but there should be a better solution with what will happen there already.
Use an anonymous function:
P>
& gt; Ddply (Iris, "species", function (x) data. Frames (wmn = weighted. Mean (X $ Sepal.Length, + X $ Petal.Length), + mn = mean (x $ Sepal.Length)) species Wmn MN1Setosa 5.016963 5.006 2Wealicular 5.978075 5.9363Virginica 6.641535 6.588> It calculates the weighted mean of the sepal, length (weighted by petal length), unrealistic Meaning and both.
Comments
Post a Comment