VOOZH about

URL: https://www.geeksforgeeks.org/r-language/remove-unnecessary-values-from-an-object-in-r-programming-na-omit-function/

⇱ How to Use na.omit in R? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Use na.omit in R?

Last Updated : 15 Jul, 2025

What are missing values?

In data analysis, missing values refer to the absence of data for a particular variable or observation. These missing values are typically represented by a special symbol or code, often denoted as "NA" (Not Available) in R and many other programming languages.

na.omit() function in R

The na.omit() function in R Programming Language is used to remove missing values (NAs) from a data frame, matrix, or vector. The name "na.omit" stands for "omit NAs." This function is particularly useful when working with datasets that contain missing values, and you want to exclude observations with missing data from your analysis.

Syntax:

na.omit(data)

Parameter:

data: Set of specified values of a data frame, matrix, or vector.

Returns: Range of values after NA omission.

Removing Missing Values from Vector

Output:

[1] 1 2 NA 4 5[1] 1 2 4 5

Removing Missing Values from matrix

Output:

 [,1] [,2] [,3] [,4]
[1,] NA NA NA NA
[2,] 1 3 5 7
[3,] 2 4 6 8 [,1] [,2] [,3] [,4]
[1,] 1 3 5 7
[2,] 2 4 6 8

Removing Missing Values from Data Frames

Output:

 ID Value
1 1 5
2 2 NA
3 3 7
4 4 8
ID Value
1 1 5
3 3 7
4 4 8


Comment

Explore