Clean HTML table with Reshape2 <p>New user of R. Can't think how to even ask the question. I scraped a webpage for HTML tables. Generally, everything went well, except for one table. Instead of there being 7 separate tables, everything got collapsed into 1 table, with the column name and the value for the first table being two separate columns, and all the other tables being rows. The results is a table with something like this: </p> <pre><code>df &lt;- data.frame(is_employed = c("Hobbies", "Has Previous Experience"), false = c("squash", "false")) </code></pre> <p>Obviously, I need to have the rows (and the column name) in the first column as their own columns, with the item in the second column as their values, preferably with underscores in the columns names. I tried: </p> <pre><code>df &lt;- dcast(df, ~is_employed, value.var = "false") </code></pre> <p>But got an error message. Then I thought to add another column, as such:</p> <pre><code>df2 &lt;- data.frame(number = c(1, 2), is_employed = c("Hobbies", "Has Previous Experience"), false = c("squash", "false")) </code></pre> <p>then I tried </p> <pre><code>df3 &lt;- dcast(df2, number ~is_employed, value.var="false") </code></pre> <p>That placed the values in the first columns as their own columns, but produced two rows (instead of 1), with NAs. I'm sure this is really basic, but I can't figure it out.</p> <p>On edit: I think this gives me what I want, but I'm away from my computer so I can't confirm:</p> <pre><code>library("dplyr") library("tidyr") mat &lt;- as.matrix(df) mat &lt;- rbind(colnames(mat), mat) colnames(mat) &lt;- c("variable", "value") df2 &lt;- as.data.frame(mat) df3 &lt;- df2 %&gt;% mutate(n = 1) %&gt;% spread(variable, value) %&gt;% select(-n) </code></pre> <p>I need to add <code>n</code> or I get NAs, but I don't like it.</p>