Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return TRUE if matrix contains any NAs?

Tags:

r

na

matrix

I wish query a matrix object and return a simple TRUE/FALSE answer if a matrix contains any NAs. So, if there are no NAs present you would get FALSE.

is.na(my.matrix) will tell me element-by-element if NAs are present, but I don't know how to sum up the results into a single answer. na.fail() looks like a better bet, but I'm still not sure how to extract a straightforward TRUE/FALSE answer.

like image 284
Roger Avatar asked Dec 21 '13 15:12

Roger


1 Answers

As Ananda Mahto pointed out, any(is.na(my.matrix)) does the trick.

like image 109
Roger Avatar answered Nov 01 '22 13:11

Roger