Re: [R] NA matrix operation

2010-12-15 Thread Joshua Wiley
Hi Patrik, If speed is an issue, an easy way to go a bit faster using Dr. Spector's code is: wh = which(is.na(mat), arr.ind=TRUE) mat[wh] = colMeans(mat, na.rm=TRUE)[wh[,2]] using that method, I can replace the NA values with column means on a 3 x 1 matrix with ~ 1% of values missing in

Re: [R] NA matrix operation

2010-12-15 Thread Phil Spector
Patrik - I don't know if it's the fastest, but, assuming your Matrix is called mat, this seems to work fairly quickly: wh = which(is.na(mat),arr.ind=TRUE) mat[wh] = apply(mat,2,mean,na.rm=TRUE)[wh[,2]] - Phil Spector

[R] NA matrix operation

2010-12-15 Thread patrik . waldmann
Dear All,   does anyone know which is the fastest way to replace NA values in a Matrix by their column mean? library(Matrix) mat Links: -- [1] http://www.ownit.se [[alternative HTML version deleted]] __