# What is the difference between NaN and NA?

I would like to know why some languages like R has both NA and NaN. What are the differences or are they equally the same? Is it really needed to have NA?

• I'd say NA is more of a "placeholder"; NaN is for (IEEE) arithmetic purposes. Commented Dec 22, 2010 at 7:04
• @JM. good way to summarize. Commented Dec 22, 2010 at 7:09
• and there is also Inf, which stands for expressions like for instance 1/0... Commented Dec 22, 2010 at 8:43
• It's explained in the documentation here. Commented Mar 15, 2013 at 13:36
• I think this question is better suited for stack overflow, but the question is too old to migrate.
– Zach
Commented Mar 15, 2013 at 13:48

?is.nan

?is.na

?NA

?NaN

But, in short:

NaN means $$\frac {0} {0}$$ -- Stands for Not a Number

NA is generally interpreted as a missing value and has various forms - NA_integer_, NA_real_, etc.

Therefore, NaN $$\neq$$ NA and there is a need for NaN and NA.

• Of note, is.na() returns TRUE for both NA and NaN, which differs from is.nan() e.g. is.na(c(0/0,NA)) vs. is.nan(c(0/0,NA)).
– chl
Commented Dec 23, 2010 at 18:04

NA is for missing data. NaN, as J.M. said is for arithmetic purpose. NaN is usually the product of some arithmetic operation, such as 0/0. NA usually is declared in advance, or is a product of operation when you try to access something that is not there:

 > a <- c(1,2)
> a[3]
[1] NA


I think of NA standing for 'Not Available', while NaN is 'Not a Number', although this is more mnemonic than explanation. By the way, I know of no language other than R (perhaps Splus?) that has both. Matlab, for example, has only NaN.

• You made a (critical) typo. "NaN is 'Not a Number'" Commented Dec 23, 2010 at 11:22
• @Peter Smit: ouch, thanks. my X server is lagging keystrokes... Commented Dec 23, 2010 at 17:23
• Several language have equivalent constructs. For instance PHP and Javascript have null and NaN.
– nico
Commented Dec 23, 2010 at 17:55

NA means the error was already there when you imported the spreadsheet into R. NaN means you caused the error after importing the data. It's the third type of error that's really hard to catch.

• what are the first two? Commented Aug 17, 2013 at 21:17
• I was being glib, but what I meant was-- NA is the first type of error, often caused by something in the imported data being the wrong type-- e.g. a numeric field containing punctuation/letters/whitespace or typos/case-variation in the levels of a factor. NaN is the second error, that more often happens when you transform data within R. The third error is data that does have a numeric value, but for one reason or another the wrong one, and it's less immediately noticeable. Again, this is not meant to be a rigorous categorization, just an informal observation. Commented Oct 24, 2016 at 19:14

NA = Not Available

NaN = Not a Number

I think once we expand the acronyms, it should be self explanatory.