How to delete a column from a data frame in R?



I am new to R and I wanted to delete column number 14 from my data frame of 21 variables? I want the column to be deleted, and not set to NULL or something, so that the columns after 14 get their numbers reassigned.



hi @Steve,

df <- data.frame(x = 1:3,y = 3:5,z = c("A","b","c"))
# By column Name:
df1 <- subset(df, select = -c(y) )
# By column number referencing:
df2 <- df[,-2] 

Hope this helps!


df$y <- NULL

can be fine?