There is an option here:
z <- Map("|", lapply(lis, is.na), lapply(bis, is.na)) bis <- Map(function(mat, idx) {mat[idx] <- NA; mat}, bis, z) lis <- Map(function(mat, idx) {mat[idx] <- NA; mat}, lis, z)
However, there may be faster / more efficient approaches due to the numerous calls to Map and lapply .
In the case of s> 2 lists, you can use the following approach (provided that each list has the same length):
Now the source lists are changed in the global environment.
Sample data:
set.seed(123) n <- 4 lis <- list( m1 = matrix(nrow=n,ncol=n,data=sample(c(NA, 1:10), n*n, TRUE)), m2 = matrix(nrow=n,ncol=n,data=sample(c(NA, 1:10), n*n, TRUE)) ) bis <- list( m1 = matrix(nrow=n,ncol=n,data=sample(c(NA, 1:10), n*n, TRUE)), m2 = matrix(nrow=n,ncol=n,data=sample(c(NA, 1:10), n*n, TRUE)) ) kis <- list( m1 = matrix(nrow=n,ncol=n,data=sample(c(NA, 1:10), n*n, TRUE)), m2 = matrix(nrow=n,ncol=n,data=sample(c(NA, 1:10), n*n, TRUE)) )