How to convert html to CSV using R programming

Asked

Viewed 229 times

0

I am with the file of the lotofacil downloaded on my desktop and' a table with the historical numbers of the lotus and this in html file://C:/Users/Rgio/Desktop/D_LOTFAC.HTM, i use R program and would like to convert it to CSV, some suggestion?

Thank you very much

  • Precisely I can not say, from a read on this link, maybe you have a way to start. http://rpubs.com/statshero/opinion-polls

1 answer

0

Personal,

with the tips I received I was able to download and work with the spreadsheet, follow the code:

Code requires XML package

library(XML)

Tf <- tempfile()

url <- "http://www1.caixa.gov.br/lotteries/lotteries/lotteries/D_lotfac.zip"

I downloaded it using "Wb mode"

download.file( url, Tf, mode = "Wb")

file.Names <-unzip(Tf)

After unzip the spreadsheet of numbers was in the D_LOTFAC.HTM file

urll <- "file://C:/Users/Rgio/Desktop/D_LOTFAC.HTM"

polls <- readHTMLTable(readLines(urll), which = 1, header = TRUE, stringsAsFactors = FALSE)

The spreadsheet contained a lot of NA’s so I cleaned it with the complete cases.

loto <- complete.cases(polls)

hist <- polls[lotus,]

I have selected only the first 17 columns where the drawn numbers are

historical <- hist[,1:17]

The result was surprising!

Thank you all

Sergio Simioni

Browser other questions tagged

You are not signed in. Login or sign up in order to post.