Corrected the mean calculation. It appears that adding the rm.na=true to the mean function corrects the values, rather than explicitly using !is.na.