rguides

How to Drop Column from Data Frame in R

You can drop column from data frame in R using three straightforward approaches. The idiomatic dplyr way is select(df, -col) — readable, composable in a pipe, and handles multiple columns with select(df, -c(col1, col2)). This is the method you’ll reach for most often in interactive analysis and reporting scripts.

library(dplyr)

df <- data.frame(name = c("Alice", "Bob"), age = c(25, 30), score = c(85, 90))
df <- df |> select(-score)
#   name age
# 1 Alice  25
# 2   Bob  30

If you prefer base R, df$score <- NULL removes the column by modifying the data frame in place — no copy, no return value needed. It’s the only column operation in base R that mutates the original object rather than producing a new one.

df$score <- NULL

For large datasets, data.table’s := NULL drops columns by reference without copying, which is faster than either dplyr or base R when you are working with millions of rows.

library(data.table)
dt <- data.table(name = c("Alice", "Bob"), age = c(25, 30), score = c(85, 90))
dt[, score := NULL]

Choose based on your pipeline: dplyr for readability and pipe-friendly composability, base R for scripts with zero dependencies, data.table for speed at scale. In practice, most R users stick with the tidyverse approach unless dataset size forces them toward data.table — the select(-col) pattern is simply the most natural way to drop column references in a chain of transformations.

See also

  • select(), Select and rename columns in dplyr
  • data.frame, Base R data frame documentation