Removing Rows with Some NAs Using na.omit() Function
Here this function will remove all rows that contain NA.
Syntax:
na.omit(dataframe)
where, dataframe is the input dataframe.
Example:
R
# create dataframe data = data.frame (names= c ( "manoj" , "bobby" , "sravan" , "deepu" , NA , NA ), id= c (1, 2, 3, NA , NA , NA ), subjects= c ( "java" , "python" , NA , NA , "java" , "python" )) # remove NA's in entire dataframe print ( na.omit (data)) |
Output:
names id subjects 1 manoj 1 java 2 bobby 2 python
How to Remove Rows with Some or All NAs in R DataFrame?
In this article, we will discuss how to remove rows with some or all NA’s in R Programming Language.
We will consider a dataframe and then remove rows in R. Let’s create a dataframe with 3 columns and 6 rows.
R
# create dataframe data = data.frame (names= c ( "manoj" , "bobby" , "sravan" , "deepu" , NA , NA ), id= c (1, 2, 3, NA , NA , NA ), subjects= c ( "java" , "python" , NA , NA , "java" , "python" )) # display print (data) |
Output: