Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show indexes of NAs?

Tags:

I have the piece to display NAs, but I can't figure it out.

try(na.fail(x)) > Error in na.fail.default(x) : missing values in object # display NAs myvector[is.na(x)] # returns NA NA NA NA 

The only thing I get from this the length of the NA vector, which is actually not too helpful when the NAs where caused by a bug in my code that I am trying to track. How can I get the index of NA element(s) ?

I also tried:

subset(x,is.na(x)) 

which has the same effect.

EDIT:

y <- complete.cases(x) x[!y] # just returns another NA NA NA NA 
like image 946
Matt Bannert Avatar asked Jan 28 '11 11:01

Matt Bannert


People also ask

How do I find missing values in R?

In R, missing values are represented by the symbol NA (not available). Impossible values (e.g., dividing by zero) are represented by the symbol NaN (not a number). Unlike SAS, R uses the same symbol for character and numeric data.

How do I index a row in a Dataframe in R?

Use the square bracket operator with df[] notation to select rows by index in R, The syntax of this notation is df[rows, columns], replace rows with the index number, index range, or list of index values.

Which element is Na in R?

C Programming from scratch- Master C Programming An NA value in R represents “Not Available” that means missing value.


1 Answers

You want the which function:

which(is.na(arr)) 
like image 51
Joel Rein Avatar answered Sep 17 '22 15:09

Joel Rein