I am creating a field for a z-score of a particular attribute. This requires calculating the mean and the standard deviation for the attribute across all features. I've been using the statistics window to get the mean and standard deviation, copying them into a field, and then doing the calculations in a third field, but I feel like that's not very efficient. I can't find a way to calculate the mean using the field calculator and my scripting skills are pretty weak.
In the Field Calculator, you can use the following Aggregate functions:
mean( "fieldName" )
stdev( "fieldName" )
Tested on QGIS 2.18
Zonal statistics plugin could be used.
We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.