Skip to content
Prev 172899 / 398521 Next

how to omit NA without using ifelse

Hi Manli. Try the replace() function as below:
replace(a,is.na(a),0) #where a is the name of your 50 x 50 matrix

Below is an example:


a<-matrix(c(sqrt(-2:3)), nrow=2) # produces a 2 x 3 matrix some of whose
elements are NaN (or NA) 
# due to square root operator on negative integers

replace(a, is.na(a), 0) 

       [,1]  [,2]      [,3]
[1,]    0    0    1.414214
[2,]    0    1    1.732051

############################
bartjoosen wrote: