As the doctor gone rogue

June 7, 2010

Import HTML table to R

Filed under: R — hypotheses @ 11:29 pm

Ever remember the day you have to copy a table from WWW paste it into excel and still have to spend more time fixing it into the format you want, and still can’t do nothing else to it beside looking at an Excel table?
During the past couple days, I have been looking around and saw that they have already incorporate this functionality in R. I also read on R-blogger today The process to import the table seems pretty simple. Here’s how.
# URL for the Google Data
tables = readHTMLTable(u)
my.table=tables[[2]] # The first element of the list is empty

Compare to the other method which import the table to a list. Then you will need to convert those list into the appropriate table.

xpathApply( htmlTreeParse("http://blabla", useInt=T), "//td", function(x) xmlValue(x))

Blog at