Readers with a background in other scripting languages may be aware of “no such animal” values, such as None in Python and undefined in Perl. R actually has two such values: NA and NULL.
In statistical data sets, we often encounter missing data, which we represent in R with the value NA. NULL, on the other hand, represents that the value in question simply doesn’t exist, rather than being existent but unknown. Let’s see how this comes into play in concrete terms.
Using NA
In many of R’s statistical functions, we can instruct the function to skip over any missing values, or NAs. Here is an example:
> x <- c(88,NA,12,168,13) > x [1] 88 NA 12 168 13 > mean(x) [1] NA > mean(x,na.rm=T) [1] 70.25 > x <- c(88,NULL,12,168,13) > mean(x) ...