title: R: How to remove columns from a dataframe dynamically
body: <p>I have a data set which has 2200 rows. I have to remove a large number of columns(e.g: around 400) at a time. This operations happens quite frequently and the columns to removed varies at each time. The columns to be removed will be in a text file.</p>
  
  <p>This is how I approached solving this.</p>
  
  <pre><code>#Reading data
  myData = read.csv("myDataFile.csv")
  
  #Getting the column names which should be deleted
  colToDelete = read.table("columnsToBeRemoved.txt")
  
  #processing the names list
  tempList = as.character(unlist(colToDelete))
  cat(paste(shQuote(tempList, type="cmd"), collapse=","))
  
  newDataSet = subset(myData, select = - ??)
  </code></pre>
  
  <p>I'm using <code>cat(paste(shQuote(tempList, type="cmd"), collapse=","))</code> to get the list of names in a comma separated string. Output of this is</p>
  
  <blockquote>
    <p>"04_ic_1306","06_iEC042_1314","13_iEcDH1_1363","18_iEcHS_1320","26_iEcolC_1368","31_iEcSMS35_1347","33_iECs_1301","34_iECUMN_1333","36_iEKO11_1354","39_iJO1366","47_iZ_1308","54_iSFxv_1172"</p>
  </blockquote>
  
  <p>I've tried subset and data.table methods but I had no luck using either of the methods. I'm getting the below error. I'm failing at specifying the string to the <strong>select</strong> command.</p>
  
  <blockquote>
    <p>Error in -a : invalid argument to unary operator</p>
  </blockquote>
  
  <p>I was mainly referring to this <a href="https://stackoverflow.com/questions/7072159/how-do-you-remove-columns-from-a-data-frame">previous stackoverflow question</a>.</p>