HOWTO · R

How to Remove Rows With NA in One Column in R

This tutorial demonstrates how to remove rows with NA in one column from a dataframe in R.

On this page

To remove rows where one chosen column contains NA, keep the rows for which is.na() is false. For a data frame df and a column named score, use the base R expression df[!is.na(df$score), ]. Here NA is R’s missing-value marker, not the literal text "NA". Because the condition checks score only, missing values in other columns do not affect which rows are retained.

Remove Rows With NA in One Column Using is.na() in R

is.na() returns a logical value for each element, marking missing values as TRUE. Negating that result and using it as the row index selects the nonmissing entries. The example assigns the result to kept, so the original df remains available. It prints the retained row count, IDs, and scores.

df <- data.frame(id = c(1, 2, 3), score = c(10, NA, 30))
kept <- df[!is.na(df$score), ]
cat("Rows retained:", nrow(kept), "\n")
cat("IDs:", paste(kept$id, collapse = ", "), "\n")
cat("Scores:", paste(kept$score, collapse = ", "), "\n")

Replace score with your column name; use df[!is.na(df$column), ] for the general pattern. The expression returns a filtered data frame, and assigning it to kept leaves df available in its original form. The row index is the key part: it applies the logical test to the selected column and keeps the matching rows across the whole data frame.

Remove Rows With NA in One Column Using complete.cases() in R

complete.cases() returns a logical value for each row, indicating whether the supplied inputs are complete. Passing just one column limits the check to that column: df[complete.cases(df$score), ]. Passing the whole data frame instead checks every column and can remove rows because of missing values outside score. Use the one-column form when the other columns should not affect retention; it selects the same rows as the is.na() pattern. This function is part of base R, so it does not require an additional package.

Remove Rows With NA in One Column Using drop_na() in R

The drop_na() function belongs to the tidyr package. Use tidyr::drop_na(df, score) to retain rows where score is present; naming the column keeps the check focused on it. If tidyr is not installed, install it with install.packages("tidyr"). This call returns a filtered data frame; assign it to a name if you want to keep and reuse the result. If you omit the column argument, drop_na(df) checks all columns, so list the target column when other columns should not determine row retention.

Remove Rows With NA in One Column Using na.omit() in R

Applied to a full data frame, na.omit(df) drops a row if any column in that row contains NA. That behavior is broader than a target-column-only filter. Applying na.omit() after selecting rows with !is.na(df$score) can still discard rows because another column is missing. For this task, use df[!is.na(df$score), ] directly; it keeps rows based on score alone. na.omit() is useful when you intend to remove rows incomplete anywhere in the data frame.

Remove Rows With NA in One Column Using subset() in R

subset() is a readable base R alternative: subset(df, !is.na(score)). It evaluates the condition using the data frame’s columns, so score refers to the column in df; other columns do not enter the condition. The returned data frame contains rows that meet it. Assign the result, for example with kept <- subset(df, !is.na(score)), to reuse it while retaining the original df. As with the bracket expression, the column name in the condition determines which rows are selected.

Remove Rows With NA in One Column Using filter() in R

The filter() function from dplyr selects rows using a condition. Call it as dplyr::filter(df, !is.na(score)) to apply the condition to score; install the package with install.packages("dplyr") if it is not available. The call returns a data frame and does not overwrite df; assign its result if you want to use the filtered data later. Since the condition names only score, missing values in other columns do not determine which rows this call retains.

Conclusion

For one chosen column, df[!is.na(df$column), ] is a direct base R solution, while complete.cases(df$column) provides a similar base R mask. Choose tidyr::drop_na() or dplyr::filter() when those packages are already part of your workflow. Take care with na.omit(df): on a whole data frame it can discard rows because of NA in columns beyond the one you meant to check. Use a single-column condition whenever only that column should control which rows remain.