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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With