Practically during any survey for data collection, getting all the information from all units is not possible as sometimes we get partial information and sometimes nothing. Therefore, it is possible that some rows in our data are completely blank and some might have partial data. The blank rows can be removed and the other empty values can be filled with methods that help to deal with missing information.
Also, reading the excel file with some empty cells may also produce errors sometimes, which ultimately affect the model accuracy. Therefore, the removal of empty cells is an important process.
To remove rows with empty cells we have a syntax in the R language, with which it is very easier for the user to remove as many numbers of empty rows in the excel file.
Steps –
- Import data
- Select rows with empty cells
- Delete such rows
- Copy to original data frame
Syntax:
data <- data[!apply(data == “”, 1, all),]
Example 1:
File used:

R
gfg_data= read.csv ( 'input_gfg.csv' )
gfg_data <- gfg_data[! apply ( is.na (gfg_data) | gfg_data == "" , 1, all),]
print (gfg_data)
|
Output:

Example 2:
File in use:

R
library (readxl)
gfg_data <- read_excel ( "Data_gfg.xlsx" )
print ( "original dataset:-" )
print (gfg_data)
gfg_data <- gfg_data[! apply ( is.na (gfg_data) | gfg_data == "" , 1, all),]
print ( "Modified dataset:-" )
print (gfg_data)
|
Output:

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
05 Apr, 2021
Like Article
Save Article