Adds function for averaging replicates within a matrix