1

I try to remove rows in HTML table with almost one empty element, represents by (NULL) using readHTMLTable() function in XLM package without success. In my code:

require(httr)
require(XML)

Function for read HTML table

readFE<- function (x, URL = ""){
FILE <- GET(url=URL)
     tables <- getNodeSet(htmlParse(FILE), "//table") 
     FE_tab <- readHTMLTable(tables[[1]], 
                        header = c("empresa","desc_projeto","desc_regiao", 
                                   "cadastrador_por","cod_talhao","descricao", 
                                   "formiga_area","qtd_destruido","latitude", 
                                   "longitude","data_cadastro"), 
                        colClasses = c("character","character","character", 
                                       "character","character","character", 
                                       "character","character","character", 
                                       "character","character"), 
                        trim = TRUE, stringsAsFactors = FALSE 
)     
     x<-NULL
     results <- x
     x<-FE_tab[-(1),]
     results <- x
     results
}

--

Exemple

tableFE<-readFE(URL="https://www.dropbox.com/s/mb316ghr4irxipr/TALHOES_AGENTES.htm?dl=1")
tableFE  

Someone could help me?

Thanks,

Alexandre

wogsland
  • 9,106
  • 19
  • 57
  • 93
Leprechault
  • 1,531
  • 12
  • 28
  • So do you want to remove the rows which has 0.00 in the entry? – Bharath Jan 15 '16 at 18:55
  • No I want to remove the rows with NULL, because I have 0 as numeric result. – Leprechault Jan 15 '16 at 18:58
  • Using `results<-results[!apply(results,1,function(x){ any(x=="(NULL)")}),]` at the end of your `readFE` function will discard any rows containing the string (NULL). – fishtank Jan 15 '16 at 19:12
  • [LINK](http://stackoverflow.com/questions/4862178/remove-rows-with-nas-in-data-frame) This link posted here has the answer for that. – Bharath Jan 15 '16 at 20:23
  • Thank you fishtank, the function work. But if I try results<-results[!apply(results,1,function(x){any(x==0.00000000)}),] for eliminated Latitude and Longitude with 0.0000 doesn't work. Can you help me? – Leprechault Jan 17 '16 at 19:37

0 Answers0