I want to replace my NA values from a matrix acquired by :
read.table(…)
Those values should be the mean of the corresponding row.
x[is.na(x)] <- mean(x, na.rm=TRUE) # for vectors or for a matrix as a whole t( apply(x, 1, function(xv) { xv[is.na(xv)] <- mean(xv, na.rm=TRUE) return(xv)} ) ) # for a row-oriented sol'n