NA
Not Available / Missing Values

Description

Several types of atomic vectors (logical, integer, double, complex, character) can contain special "not available" or "missing" values, which are displayed as NA. Most operations on an NA value produce an NA.

Usage

NA
NA_integer_
NA_real_
NA_complex_
NA_character_
NaN

is.na(x) ## S3 method for class 'data.frame': is.na(x) ## S3 method for class 'POSIXlt': is.na(x)

is.na(x) <- value ## Default S3 method: is.na(x) <- value ## S3 method for class 'factor': is.na(x) <- value

Arguments

x any object.
value a vector of indices or a logical vector specifying the elements to be set to NA.

Details

Value
is.nareturns a logical vector of the same length as x, containing TRUE for every missing value in x, and FALSE for every non-missing value.
is.na<-returns the modified variable. Any attributes from the original x variable, such as the dim attribute of a matrix, are maintained.
See Also
is.finite, is.nan.
Examples
NA; NA_integer_; NA_real_; NA_complex_; NA_character_
# NA values of different types print the same:
#  [1] NA
#  [1] NA
#  [1] NA
#  [1] NA
#  [1] NA

is.na(NA) # [1] TRUE is.na(NaN) # [1] TRUE is.nan(NA) # [1] FALSE is.nan(NaN) # [1] TRUE

x <- c( 1, 3, NA, 5, NA ) is.na(x) # [1] FALSE FALSE TRUE FALSE TRUE is.na(x) <- 2 # Set the second element to NA is.na(x) # [1] FALSE TRUE TRUE FALSE TRUE

x <- factor(c("a", "b", "c", NA, "b")) is.na(x) # [1] FALSE FALSE FALSE TRUE FALSE is.na(x) <- 1:2 # Set the first and second element to NA is.na(x) # [1] TRUE TRUE FALSE TRUE FALSE

x <- 1:5 is.na(x) <- x>3 # specify elements with logical vector is.na(x) # [1] FALSE FALSE FALSE TRUE TRUE

x <- data.frame(x1=c(1,2,3), x2=c(NA,5,6), x3=c(7,NA,9)) # Return a logical matrix x with logical columns indicating NA elements is.na(x) # returns a logical matrix indicating NA elements in x # x1 x2 x3 # [1,] FALSE TRUE FALSE # [2,] FALSE FALSE TRUE # [3,] FALSE FALSE FALSE is.na(x) <- 2 # Set all elements of the second column to NA

Package base version 6.0.0-69
Package Index