Section 31 Missing values
31.1 Missing values in R
NA
NaN
is.na()
to test objects if they are NAis.nan()
to test object for NaNNA
values have a class- integer
NA
, characterNA
, logicalNA
- integer
A
NaN
value is alsoNA
but the converse is not trueA special number:
Inf
Inf
and-Inf
are positive and negative infinity whereasNaN
means ‘Not a Number’.
31.2 Example: Numeric vector
<- c(1, 2, NA, 10, 3)
x is.na(x)
is.nan(x)
<- c(1, 2, NaN, NA, 4)
y is.na(y)
is.nan(y)
sqrt(-2)
is.nan(sqrt(-2))
5/0
31.3 Example: Character vector
<- c('a', 'b', NA, 'd', 'e')
x is.na(x)
is.nan(x)
<- c('a', 'b', NaN, NA, 'e')
y is.na(y)
is.nan(y)
31.4 Example: Logical vector
<- c(T, F, NA, TRUE, FALSE)
x is.na(x)
is.nan(x)
<- c(T, F, NaN, NA, TRUE, FALSE)
y is.na(y)
is.nan(y)