Thursday, February 17, 2011

Locating missing values with is.na()

When getting data ready for analysis, a very handy function is "is.na." It prints out a list of "TRUE" and "FALSE" responses for the status of every entry in a vector or column.

I have data from an experiment where I know the plot number is missing for a few entries. I can quickly identify these like this:

First, use is.na on the plot column and store the results (a LONG list of 2000 entries) to an object "na_plot"

na_plot<-is.na(reboot1$plot)

Second, use the which() function to query the list for the entries where the answer to the question "is.na" is "TRUE"

which(na_plot == TRUE)

This gives me the index number of the entries that are NA.

No comments:

Post a Comment