Functions for WPS algorithms to calculate stats by group.

I didn't use ROxygen for these, but the man pages are pretty decent. Please have a look over an merge if nothing looks horrible. I did an architecture review with Jordan and Laura and have already dealt with their feedback.