Setting NA in a matrix using another logical matrix
The original poster added a comment saying he'd figured out a solution, then almost immediately deleted it:
m[ !i ] <- NA
I had started an answer that offered a slightly different solution using the is.na<-
function:
is.na(m) <- !i
Both solutions seem to be reasonable R code that rely upon logical indexing. (The i
matrix structure is not actually relied upon. A vector of the proper length and entries would also have preserved the matrix structure of m
.)