Não consegui rodar, alguém sabe o motivo?


> require(RCurl)); require(XML)

Loading required package: RCurl

Loading required package: bitops

Loading required package: XML

> url0 <- "https://www.dropbox.com/s/znmr0lwda2y6fc5/BD_teste2.html?dl=1";

> url1 <- gsub("(^.*)(/s/.*)(\\?.*$)", "https://dl.dropboxusercontent.com\\2";, 
> url0); url1

[1] "https://dl.dropboxusercontent.com/s/znmr0lwda2y6fc5/BD_teste2.html";

> # [1] "https://dl.dropboxusercontent.com/s/znmr0lwda2y6fc5/BD_teste2.html";

>

> page <- getURL(url1)

Error in function (type, msg, asError = TRUE)  :

  SSL certificate problem, verify that the CA cert is OK. Details:

error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify 
failed



De: R-br [mailto:[email protected]] Em nome de Éder Comunello
Enviada em: sexta-feira, 29 de janeiro de 2016 09:41
Para: ASANTOS
Cc: [email protected]
Assunto: Re: [R-br] RES: Criar função para tirar a média entre grupos sob 
condições dadas



Alexandre, bom dia!



Não havia atentado para o problema na importação das tabelas, sendo necessário 
definir as classes. Além disso, na função você deve se referir a "db" antes que 
"tableFE" e  "x" é definido internamente por lapply().





### <code r>

require(RCurl); require(XML)

url0 <- "https://www.dropbox.com/s/znmr0lwda2y6fc5/BD_teste2.html?dl=1";

url1 <- gsub("(^.*)(/s/.*)(\\?.*$)", "https://dl.dropboxusercontent.com\\2";, 
url0); url1

# [1] "https://dl.dropboxusercontent.com/s/znmr0lwda2y6fc5/BD_teste2.html";



page <- getURL(url1)

tableFE <- readHTMLTable(page, head=T)[[1]]

str(tableFE) ### todas variáveis estão como fatores - corrigir!



classes <- c(rep("factor", 6), rep("numeric", 4), "factor")

tableFE <- readHTMLTable(page, head=T, colClasses=classes)[[1]]

str(tableFE) ### OK!

head(tableFE)



##Agregando os resultados

aggPestFE <- function(db=tableFE, key="descricao"){

lista  <- split(db, db[key])

result <- lapply(lista, function(x) aggregate(x[,7:8], 
by=list(x[,3],x[,2],x[,5]), mean))

return(result)

}



### Devido aos "defaults", obtém mesmos resultados nas três formas que seguem:

aggPestFE()[5]

aggPestFE(tableFE)[5]

aggPestFE(tableFE, "descricao")[5]

# $`Lagartas Desfolhadoras`

#   Group.1           Group.2 Group.3 formiga_area qtd_destruido

# 1      GN             Chale      26            0          62.5

# 2      RD Corrego da Coruja      26            0          50.0

# 3      GN      Aeroporto II      28            0          75.0



### </code>




​

================================================
Éder Comunello

PhD Student in Agricultural Systems Engineering (USP/Esalq)

Brazilian Agricultural Research Corporation (Embrapa)

Dourados, MS, Brazil [22 16.5'S, 54 49.0'W]









---
Este email foi escaneado pelo Avast antivírus.
https://www.avast.com/antivirus
_______________________________________________
R-br mailing list
[email protected]
https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br
Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia) e forne�a c�digo 
m�nimo reproduz�vel.

Responder a