Scraping a table from the web with R

June 11, 2015 in #r

It's rather basic task. However, more complicated data structures require some fine-tuning.

library(XML)  
theurl <- "http://goo.gl/2X5LK"  
dealer.codes <- readHTMLTable(theurl)  
n.rows <- unlist(lapply(dealer.codes, function(t) dim(t)[1]))  
dealer.codes <- dealer.codes[[which.max(n.rows)]]