Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

need weighted_mean() to avoid common problem #27

Open
behrman opened this issue Mar 6, 2019 · 0 comments
Open

need weighted_mean() to avoid common problem #27

behrman opened this issue Mar 6, 2019 · 0 comments

Comments

@behrman
Copy link

behrman commented Mar 6, 2019

I teach classes where students learn and use the tidyverse, and I've been noticing that a large proportion are getting wrong results from weighted.mean() without knowing it.

The students learn to use dplyr::count() with the wt argument. When they use weighted.mean(), they also use the wt argument. The weights argument for weighted.mean() is w not wt, and since is uses ..., those who use wt don't receive an error message. Instead, weighted.mean() returns the unweighted mean, which is almost certainly not what the user intended.

May I suggest a new tidyverse function weighted_mean() that uses wt for its weights argument to be consistent with count() and that gives an error message when used incorrectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant