implemented mean with na.rm and double loop