Skip to content
Related Articles

Related Articles

Delete rows with empty cells from Excel using R

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 05 Apr, 2021

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


data <- data[!apply(data == “”, 1, all),]

Example 1:

File used:


gfg_data <- gfg_data[!apply( | gfg_data == "", 1, all),]


Example 2:

File in use:


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


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!