Hello fellow R users,

I have a matrix computation that I imagine should be relatively easy to do, 
however I cannot figure out a nice way to do it. I have two matrices, for 
example

mat1 <- matrix(c(1:5,rep(NA,5), 6:10), nrow=3, byrow=T)
mat2 <- matrix(c(2:6, 6:10, rep(NA,5)), nrow=3, byrow=T)

I'd like to compute the element-wise average for non-NA entries. Of course

(mat1+mat2)/2

does not work for the final two rows because of the NA's. Are there any elegant 
ways to accopmlish this without writing a loop with indices?

Thanks in advance for any assistance.

Greg


       
---------------------------------

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to