I have matrix data
data<-matrix(cbind(c(0,0,0),c(NA,0,1),c(1,1,1),c(0,1,1)),ncol=3)
and I want to create a new matrix by checking each element of the data and
put value 0 if i have NA and 1 otherwise.
For this reason i made the function below
pdata<-matrix(NA,ncol=ncol(data),nrow=nrow(data))
pdata<-sapply(1:nrow(data),function(i) sapply (1:ncol(data),function(j)
if (is.na(data[i,j])) {pdata[i,j]<-0} else {pdata[i,j]<-1}
))
pdata<-matrix(t(pdata),ncol=ncol(data),nrow=nrow(data))
with pdata