Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R code: webscraping

Tags:

r

I am trying to webscrape an OECD table with R.

library(XML)
OECD <- readHTMLTable('http://stats.oecd.org/Index.aspx?DataSetCode=MEI_CLI')
OECD<- data.frame(rawOECD[[1]])

I have managed to get the basic table with the above code but I am having trouble getting it into a presentable form.

I would be grateful for your help.

Kind regards,

Adam

like image 512
user1162244 Avatar asked Oct 25 '25 04:10

user1162244


1 Answers

How about this?

library(XML)
OECD <- readHTMLTable('http://stats.oecd.org/Index.aspx?DataSetCode=MEI_CLI',stringsAsFactors = FALSE)

n.rows <- unlist(lapply(OECD, function(t) dim(t)[1]))
out <-as.data.frame(OECD[[which.max(n.rows)]])
colnames(out) <-c("Date",out[7,-ncol(out)]) #add row names
out <-out[-(1:9),]  #clean up
like image 67
Pierre Lapointe Avatar answered Oct 26 '25 17:10

Pierre Lapointe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!