2

Is this the correct way to delete a column from a dataframe in R? Or there is a better way?

dataframe$column <- NULL
Nymeria123
  • 51
  • 1
  • 8

2 Answers2

0

Another way is by using negative subscripts:

Say, you want to remove column #2 from the data frame:

 df <- df[,-2]

If you want to remove several columns, use c; for example:

 df <- df[,-c(2, 5, 7:10)]
Chris Ruehlemann
  • 15,379
  • 3
  • 11
  • 27
0

using dplyr from tidyverse you can pipe in the ability to drop a single or multiple columns:

library(tidyverse)

dataframe <- dataframe %>%
  select(-column)
nycrefugee
  • 1,444
  • 1
  • 9
  • 21