2

Suppose I have a list:

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))
  )

I want to know how many NA (NaN) we have in this list?

bic ton
  • 1,284
  • 1
  • 9
  • 16

2 Answers2

6

This could be simpler:

sum(is.na(unlist(lis)))
Frank
  • 66,179
  • 8
  • 96
  • 180
RHertel
  • 23,412
  • 5
  • 38
  • 64
2
sum(sapply(lis, function(i) sum(is.na(i))))
[1] 2
fdetsch
  • 5,239
  • 3
  • 30
  • 58