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