Drop Columns From Dataframe

Original Source: http://stackoverflow.com/questions/4605206/drop-columns-r-data-frame

Want to learn more? I recommend working through: R for Data Science, R Cookbook, and R Graphics Cookbook.

# create a dataframe with three columns
df <- data.frame(x = runif(100), y = runif(100), z = runif(100))
# drop columns y and z
df <- subset(df, select = -c(y, z) )
# only keep column x (thus dropping y and z)
df <- subset(df, select = c(x))