-6
dataframename <- data.frame(
  col1=1:10,
  col2=10:1,
  col3=1:50,
  col4=11:20
) 

Consider the above dataframe and I want to remove column 1 and column 4.
1. Without using any package.
2. The answer should be in dataframe format only and not vector results.

Parth Pandya
  • 39
  • 1
  • 12
  • 5
    google search: [Link1](http://stackoverflow.com/questions/4605206/drop-data-frame-columns-by-name), [Link2](http://stackoverflow.com/questions/6286313/remove-an-entire-column-from-a-data-frame-in-r), [Link3](http://stackoverflow.com/questions/7072159/how-do-you-remove-columns-from-a-data-frame) – Sotos Jan 24 '17 at 11:17

1 Answers1

-2
###Use subset command:###
dataframename <- subset(dataframename, select = -c(col1,col4) )

###One more approach is you can use list(NULL) to the dataframe:###
dataframename[,c("col1","col4")] <- list(NULL)
David Arenburg
  • 91,361
  • 17
  • 137
  • 196
Sriharsha
  • 150
  • 3
  • 16