NA is a logical constant of length 1 which contains a missing value indicator.
NA can be coerced to any other vector type except raw. There are also constants
NA_character_ of the other atomic vector types which support missing values: all of these are reserved words in the R language.
The generic function
is.na indicates which elements are missing.
The generic function
is.na<- sets elements to
NA is.na(x) ## S3 replacement method for class 'data.frame': is.na((x) is.na(x) <- value)
- an R object to be tested: the default method handles atomic vectors, lists and pairlists.
- a suitable index vector for use with
NA of character type is distinct from the string
"NA". Programmers who need to specify an explicit string
NA should use
NA_character_ rather than
"NA", or set elements to
is.na(x) works elementwise when
x is a
list. It is generic: you can write methods to handle specific classes of objects, see InternalMethods. A complex value is regarded as
NA if either its real or imaginary part is
is.na<- may provide a safer way to set missingness. It behaves differently for factors, for example.
NA will normally result in
NA: a possible exception is where
NaN is also involved, in which case either might result.
The default method for
is.na applied to an atomic vector returns a logical vector of the same length as its argument
TRUE for those elements marked
NA or, for numeric or complex vectors,
NaN (!) and
names attributes are preserved.
The default methods also works for lists and pairlists:
is.na, elementwise the result is false unless that element is a length-one atomic vector and the single element of that vector is regarded as
NaN (note that any
is.na methods for the class of the atomic vector is ignored).
The data frame method for
is.na returns a logical matrix with the same dimensions as the data frame, and with dimnames taken from the row and column names of the data frame.
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.
Chambers, J. M. (1998) Programming with Data. A Guide to the S Language. Springer.
Documentation reproduced from R 3.0.1. License: GPL-2.