Is this the correct way to delete a column from a dataframe in R? Or there is a better way?
dataframe$column <- NULL
Is this the correct way to delete a column from a dataframe in R? Or there is a better way?
dataframe$column <- NULL
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)]
using dplyr
from tidyverse
you can pipe in the ability to drop a single or multiple columns:
library(tidyverse)
dataframe <- dataframe %>%
select(-column)