title: Convert HTML tables to R data frame
body: <pre><code>&lt;TABLE  cellspacing=1 cellpadding=7 rules=all frame=Box border=1&gt;
  &lt;thead&gt;
  &lt;TR&gt;
   &lt;TD ROWSPAN=2 ALIGN=CENTER VALIGN=CENTER&gt;&amp;nbsp;&lt;/TD&gt;
   &lt;TD COLSPAN=6 ALIGN=CENTER&gt;1a. My peers make a positive impact my work environment.&lt;/TD&gt;
   &lt;TD ALIGN=CENTER&gt;Number&lt;/TD&gt;
  &lt;/TR&gt;
  &lt;TR&gt;
   &lt;TD ALIGN=CENTER&gt;Strongly agree  &lt;br&gt;         &lt;/TD&gt;
   &lt;TD ALIGN=CENTER&gt;Generally agree &lt;br&gt;         &lt;/TD&gt;
   &lt;TD ALIGN=CENTER&gt;Neither agree nor&lt;br&gt;disagree&lt;/TD&gt;
   &lt;TD ALIGN=CENTER&gt;Generally disagree&lt;br&gt;       &lt;/TD&gt;
   &lt;TD ALIGN=CENTER&gt;Strongly disagree&lt;br&gt;        &lt;/TD&gt;
   &lt;TD ALIGN=CENTER&gt;No basis to judge&lt;br&gt;        &lt;/TD&gt;
   &lt;TD ALIGN=CENTER&gt;of Cases&lt;/TD&gt;
  &lt;/TR&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
  &lt;TR&gt;
   &lt;TD ALIGN=LEFT VALIGN=TOP&gt;  Company-Wide                                     &lt;/TD&gt;
   &lt;TD ALIGN=RIGHT VALIGN=BOTTOM&gt;        44.1&lt;/TD&gt;
   &lt;TD ALIGN=RIGHT VALIGN=BOTTOM&gt;        44.9&lt;/TD&gt;
   &lt;TD ALIGN=RIGHT VALIGN=BOTTOM&gt;         6.6&lt;/TD&gt;
   &lt;TD ALIGN=RIGHT VALIGN=BOTTOM&gt;         2.6&lt;/TD&gt;
   &lt;TD ALIGN=RIGHT VALIGN=BOTTOM&gt;         1.6&lt;/TD&gt;
   &lt;TD ALIGN=RIGHT VALIGN=BOTTOM&gt;         0.1&lt;/TD&gt;
   &lt;TD ALIGN=RIGHT VALIGN=BOTTOM&gt;   2,014&lt;/TD&gt;
  &lt;/TR&gt;
  &lt;TR&gt;
   &lt;TD ALIGN=LEFT VALIGN=TOP&gt; Region 1                                 &lt;/TD&gt;
   &lt;TD ALIGN=RIGHT VALIGN=BOTTOM&gt;        45.6&lt;/TD&gt;
   &lt;TD ALIGN=RIGHT VALIGN=BOTTOM&gt;        45.2&lt;/TD&gt;
   &lt;TD ALIGN=RIGHT VALIGN=BOTTOM&gt;         5.7&lt;/TD&gt;
   &lt;TD ALIGN=RIGHT VALIGN=BOTTOM&gt;         2.1&lt;/TD&gt;
   &lt;TD ALIGN=RIGHT VALIGN=BOTTOM&gt;         1.4&lt;/TD&gt;
   &lt;TD ALIGN=RIGHT VALIGN=BOTTOM&gt;         0.1&lt;/TD&gt;
   &lt;TD ALIGN=RIGHT VALIGN=BOTTOM&gt;   1,699&lt;/TD&gt;
  &lt;/TR&gt;
  &lt;TR&gt;
   &lt;TD ALIGN=LEFT VALIGN=TOP&gt;Division 1            &lt;/TD&gt;
   &lt;TD ALIGN=RIGHT VALIGN=BOTTOM&gt;        52.9&lt;/TD&gt;
   &lt;TD ALIGN=RIGHT VALIGN=BOTTOM&gt;        39.7&lt;/TD&gt;
   &lt;TD ALIGN=RIGHT VALIGN=BOTTOM&gt;         4.1&lt;/TD&gt;
   &lt;TD ALIGN=RIGHT VALIGN=BOTTOM&gt;         2.5&lt;/TD&gt;
   &lt;TD ALIGN=RIGHT VALIGN=BOTTOM&gt;         0.8&lt;/TD&gt;
   &lt;TD ALIGN=RIGHT VALIGN=BOTTOM&gt;0&lt;/TD&gt;
   &lt;TD ALIGN=RIGHT VALIGN=BOTTOM&gt;     121&lt;/TD&gt;
  &lt;/TR&gt;
  &lt;/tbody&gt;
  &lt;/TABLE&gt;
  &lt;hr&gt;&lt;A NAME="IDX1"&gt;&amp;nbsp;&lt;/A&gt;
  </code></pre>
  
  <p>I have an HTML file that contains several tables of the sort above. I would like to convert them into a data frame where each survey question, currently in the table header, would appear in a column. The percent responding to each question would remain in a column, as would the response levels. Not all questions have the same number of responses (i.e. some are on a five point scale, others are on a nine point scale). I tried readHTMLTable and then do.call rbind on that result, but cannot obtain the data frame of interest because the number of columns is not identical. I welcome any advice on how to proceed. thanks!</p>
  
  <p>edit:</p>
  
  <pre><code>library(xml)
  library(dplyr)
  questions&lt;-readHTMLTable(files[8], trim=T, as.data.frame=T, header=T)
  data&lt;-bind_rows(questions)
  </code></pre>
  
  <p>Results in the data frame I want, but because some questions have more response levels than others, the "number of cases" data does not consistently appear in one column. Is there a way for me to name the last column of each table before merging?</p>