Method 3 : Using omit() method
omit() method is used to remove the NA values directly by resulting in the non-NA values and omitted NA values indexes.
Syntax:
na.omit(vector)
where the vector is the input vector
Return type:
- Returns the non-NA values
- Returns the indexes of NA values which are removed from the vector
Note: Indexing starts with 1
Example: R program to consider a vector and remove NA values
R
# create a vector with integers along with NA a= c (1,2, NA ,4,5, NA ,4,5,6, NA ) # display print (a) print ( "_______________________" ) # remove NA using omit() function a= na.omit (a) # display vector print (a) |
Output:
[1] 1 2 NA 4 5 NA 4 5 6 NA [1] "_______________________" [1] 1 2 4 5 4 5 6 attr(,"na.action") [1] 3 6 10 attr(,"class") [1] "omit"
Remove NA Values from Vector in R
In this article, we are going to discuss how to remove NA values from the vector.