Method 2 : Removing Rows with Some NAs Using complete.cases() Function
Here this function will remove the NAs in the dataframe.
Syntax:
dataframe[complete.cases(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 (data[ complete.cases (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:
Contact Us