From the course: R for Data Science: Lunch Break Lessons

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

weighted.mean

weighted.mean

- [Instructor] Let's talk about mean versus weighted mean. Now I like fruit, I like apples, I really like peaches, I don't like brusselsprouts. Somebody wants to give me a basket full of fruit, and I need to evaluate which one I want. So let's set up the ability to do a weighted mean versus a mean. What you're looking at right now is apples, which has been assigned a one, peaches assigned two and brusselsprouts has been assigned a negative one. And I put all three of these into a vector called fruitWeights. Let's look at Bob's basket and determine if I like it. Well, I can use mean. And I'll type in BobsBasket. And I can see that BobsBasket receives a rating of 6.66. Now I'm going to do the same for JanesBasket. Well, JanesBasket only receives a five. So in this case, I should prefer BobsBasket, but if you look at the contents you'll see that there is a lot of brusselsprouts in that basket, and I do not like brusselsprouts. So instead of using mean, what I should be using instead is…

Contents