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

- NA is a logical vector containing a single logical missing value. NA_integer_, NA_real_, NA_complex_, and NA_character_ contain the missing values for integers, doubles, complex, and character vectors, respectively.
- NaN is a second kind of missing double value, the so-called "Not a Number" value. This can be produced by numerical computation. For example, the computations 0/0 and Inf - Inf both produce the result NaN. is.na returns TRUE both for NA and NaN values. is.nan returns TRUE for NaN values, but FALSE for other NA values.
- is.na is used to test for missing values. It is a generic, and some S3 methods are implemented. Note that the logical expression x == NA is different from is.na(x). Its value is a vector of the same length as x, all of whose values are NA.
- is.na<- is used to set a subset of x to NA. It is a generic, and some S3 methods are implemented.
- is.na.data.frame returns a matrix with the same column names as x, where each column is the result of applying is.na to the corresponding column of x.

Value

is.na | returns 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.1.5-18
Package Index