On Aug 17, 2012, at 8:28 PM, Yingwei Lee wrote: > m=matrix(c(1:4, c(0, 0, 0, 0), c(1, 0, 1, 1)), nc=4, byrow=TRUE) is.na(m) <- m==0 rowMeans(m, na.rm=T) #[1] 2.5 NaN 1.0 -- David Winsemius, MD Alameda, CA, USA