NA NA_integer_ NA_real_ NA_complex_ NA_character_ NaNis.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
x | any object. |
value | a vector of indices or a logical vector specifying the elements to be set to NA. |
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. |
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] NAis.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