Skip to content
Prev 333875 / 398513 Next

Removing NAs from matrix

Hello,

Your code corrected would be


mean.matrix[, 1] <- apply(mat, 1, mean, na.rm = TRUE)

(No need for the for loop).
Even better would be to avoid loops and use the base R function ?rowMeans.

mean.matrix[, 1] <- rowMeans(mat, na.rm = TRUE)

Hope this helps,

Rui Barradas

Em 01-12-2013 12:16, Amie Hunter escreveu: