I have a matrix that looks like this
a = matrix(c(5,10,NaN,NaN,4,5,3,NaN,NaN,2), nr=5)
a
     [,1] [,2]
[1,]    5    5
[2,]   10    3
[3,]  NaN  NaN
[4,]  NaN  NaN
[5,]    4    2
Now I want to have those NaN's replaced by zeros. I know is.nan function will return the indices of those elements, but how can I make use of the fact that if a NaN exists in a row, then all elements of that row are all NaN's (as in the example above, rows 3 and 4). Thanks!