If you suspect that some of your columns are factors, you can use the following code to detect and change them to numeric.
inx <- sapply(mat, inherits, "factor") mat[inx] <- lapply(mat[inx], function(x) as.numeric(as.character(x)))
Then try the following.
mat[] <- lapply(mat, function(x) {x[is.na(x)] <- 0; x}) mat
And here is the data.
mat <- structure(list(A = c(1L, 0L, 0L, NA, 0L, 1L, 0L), B = c(1L, 0L, 0L, NA, 1L, 1L, 0L), C = c(0L, 1L, 0L, NA, 0L, 1L, 1L), E = c(NA, NA, NA, NA, 1L, 0L, 0L), F = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), D = c(0L, 0L, 1L, NA, 0L, 0L, 1L), Q = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), Z = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_)), .Names = c("A", "B", "C", "E", "F", "D", "Q", "Z"), row.names = c("1", "2", "3", "4", "5", "6", "7"), class = "data.frame")