R Language Removing incomplete rows


There might be times where you have a data frame and you want to remove all the rows that might contain an NA value, for that the function complete.cases is the best option.

We will use the first 6 rows of the airquality dataset to make an example since it already has NAs

x <- head(airquality)

This has two rows with NAs in the Solar.R column, to remove them we do the following

x_no_NA <- x[complete.cases(x),]

The resulting dataframe x_no_NA will only have complete rows without NAs