Import HTML table to R

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))


2 thoughts on “Import HTML table to R”

  1. Yeah — I discovered this 2 weeks ago on that flowdata blogsite. It’s pretty cool. I hope I remember this function exist when I do need to use it.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.