replaced var/mean/sum in apply() calls by base::var, base::mean and base::sum to avoid trouble if var/mean/sum was redefined by the user (problem reported by John Prindle)