Functions for ranking and weighted average()