<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Éder,<br>
    <br>
       A sua solução não funcionou com meu exemplo real e não consigo
    achar o problema, sendo que:<br>
    <br>
    ##  Função de leitura do banco de dados <br>
    readFE<- function (x, URL = ""){<br>
    FILE <- GET(url=URL)<br>
         tables <- getNodeSet(htmlParse(FILE), "//table") <br>
         FE_tab <- readHTMLTable(tables[[1]], <br>
                            header =
    c("empresa","desc_projeto","desc_regiao", <br>
                                      
    "cadastrador_por","cod_talhao","descricao", <br>
                                      
    "formiga_area","qtd_destruido","latitude", <br>
                                       "longitude","data_cadastro"), <br>
                            colClasses =
    c("character","character","character", <br>
                                          
    "character","numeric","character", <br>
                                          
    "numeric","numeric","numeric", <br>
                                           "numeric","character"), <br>
                            trim = TRUE, stringsAsFactors = FALSE <br>
    )     <br>
         x<-NULL<br>
         results <- x<br>
         x<-FE_tab[-(1),]<br>
         results <- x<br>
        
    results<-results[!apply(results,1,function(x){any(x=="(NULL)")}),]<br>
         results<br>
    }<br>
    #--#<br>
tableFE<-readFE(URL=<a class="moz-txt-link-rfc2396E" href="https://www.dropbox.com/s/znmr0lwda2y6fc5/BD_teste2.html?dl=1">"https://www.dropbox.com/s/znmr0lwda2y6fc5/BD_teste2.html?dl=1"</a>)<br>
    tableFE<-tableFE[1:163,1:11]<br>
    head(tableFE)<br>
    <br>
    ##Agregando os resultados<br>
    lista <- split(tableFE, tableFE$descricao)<br>
    lapply(lista, function(x) aggregate(x[,7:8], by=list(x[,2]), mean)) 
    ## Não funciona<br>
    <br>
    <br>
    mas se eu faço item por item funciona e não sei porque, sendo:<br>
    <br>
    aggregate(lista$`Psilideo-de-Concha`[,7:8],
    by=list(lista$`Psilideo-de-Concha`[,2],lista$`Psilideo-de-Concha`[,5]),
    mean)<br>
    <br>
    Poderia me dar mais um help?<br>
    <br>
    Obrigado,<br>
    <br>
    Abraços<br>
    <pre class="moz-signature" cols="72">-- 
======================================================================
Alexandre dos Santos
Proteção Florestal 
IFMT - Instituto Federal de Educação, Ciência e Tecnologia de Mato Grosso
Campus Cáceres
Caixa Postal 244
Avenida dos Ramires, s/n
Bairro: Distrito Industrial 
Cáceres - MT                      CEP: 78.200-000
Fone: (+55) 65 8132-8112 (TIM)   (+55) 65 9686-6970 (VIVO)
<a class="moz-txt-link-abbreviated" href="mailto:e-mails:alexandresantosbr@yahoo.com.br">e-mails:alexandresantosbr@yahoo.com.br</a> 
        <a class="moz-txt-link-abbreviated" href="mailto:alexandre.santos@cas.ifmt.edu.br">alexandre.santos@cas.ifmt.edu.br</a> 
Lattes: <a class="moz-txt-link-freetext" href="http://lattes.cnpq.br/1360403201088680">http://lattes.cnpq.br/1360403201088680</a>
OrcID: orcid.org/0000-0001-8232-6722 
Researchgate: <a class="moz-txt-link-freetext" href="https://www.researchgate.net/profile/Alexandre_Santos10">https://www.researchgate.net/profile/Alexandre_Santos10</a>                       
LinkedIn: <a class="moz-txt-link-freetext" href="https://br.linkedin.com/in/alexandre-dos-santos-87961635">https://br.linkedin.com/in/alexandre-dos-santos-87961635</a>
======================================================================
</pre>
    <div class="moz-cite-prefix">Em 21/01/2016 13:37, Éder Comunello
      escreveu:<br>
    </div>
    <blockquote
cite="mid:CABmC8g=SOj_eV7JXcD7oFrrtG6nxOWrJuagSihtY0yz49HKrmw@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div class="gmail_default"
          style="font-family:verdana,sans-serif">Senhores, boa tarde!</div>
        <div class="gmail_default"
          style="font-family:verdana,sans-serif"><br>
        </div>
        <div class="gmail_default"
          style="font-family:verdana,sans-serif">Também não entendi
          direito. Mas talvez a ideia abaixo possa fazer algum
          sentido... </div>
        <div class="gmail_default"
          style="font-family:verdana,sans-serif"><br>
        </div>
        <div class="gmail_default" style="">
          <div class="gmail_default"><font face="monospace, monospace">###
              <code r></font></div>
          <div class="gmail_default"><font face="monospace, monospace">tableFE
              <- structure(list(Bichos = structure(c(2L, 1L, 3L, 1L,
              3L, 2L, 3L, </font></div>
          <div class="gmail_default"><font face="monospace, monospace">2L,
              1L, 3L, 1L, 3L, 2L, 3L, 3L), .Label = c("Barata",
              "Besouros", </font></div>
          <div class="gmail_default"><font face="monospace, monospace">"Formiga"),
              class = "factor"), Talhao = c(73, 15, 74, 75, 15, </font></div>
          <div class="gmail_default"><font face="monospace, monospace">15,
              15, 73, 15, 15, 73, 15, 73, 74, 74), Projeto =
              structure(c(1L, </font></div>
          <div class="gmail_default"><font face="monospace, monospace">3L,
              2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L),
              .Label = c("Abre Campo", </font></div>
          <div class="gmail_default"><font face="monospace, monospace">"Vitoria",
              "Volta Redonda"), class = "factor"), Injuria = c(25, </font></div>
          <div class="gmail_default"><font face="monospace, monospace">100,
              0, 25, 0, 100, 0, 50, 25, 0, 25, 0, 25, 0, 0), Area =
              c(0, </font></div>
          <div class="gmail_default"><font face="monospace, monospace">0,
              12.5, 0, 7.5, 0, 1.5, 0, 0, 23.8, 0, 5.3, 0, 2, 11.3)),
              .Names = c("Bichos", </font></div>
          <div class="gmail_default"><font face="monospace, monospace">"Talhao",
              "Projeto", "Injuria", "Area"), row.names = c(NA, -15L</font></div>
          <div class="gmail_default"><font face="monospace, monospace">),
              class = "data.frame")</font></div>
          <div class="gmail_default"><font face="monospace, monospace"><br>
            </font></div>
          <div class="gmail_default"><font face="monospace, monospace">lista
              <- split(tableFE, tableFE$Bichos); lista</font></div>
          <div class="gmail_default"><font face="monospace, monospace"><br>
            </font></div>
          <div class="gmail_default"><font face="monospace, monospace">lapply(lista,
              function(x) aggregate(x[,4:5], by=list(x$Projeto), mean))</font></div>
          <div class="gmail_default"><font face="monospace, monospace">#
              $Barata</font></div>
          <div class="gmail_default"><font face="monospace, monospace">#
                      Group.1 Injuria Area</font></div>
          <div class="gmail_default"><font face="monospace, monospace">#
              1    Abre Campo    25.0    0</font></div>
          <div class="gmail_default"><font face="monospace, monospace">#
              2       Vitoria    25.0    0</font></div>
          <div class="gmail_default"><font face="monospace, monospace">#
              3 Volta Redonda    62.5    0</font></div>
          <div class="gmail_default"><font face="monospace, monospace"># </font></div>
          <div class="gmail_default"><font face="monospace, monospace">#
              $Besouros</font></div>
          <div class="gmail_default"><font face="monospace, monospace">#
                      Group.1 Injuria Area</font></div>
          <div class="gmail_default"><font face="monospace, monospace">#
              1    Abre Campo      25    0</font></div>
          <div class="gmail_default"><font face="monospace, monospace">#
              2       Vitoria     100    0</font></div>
          <div class="gmail_default"><font face="monospace, monospace">#
              3 Volta Redonda      50    0</font></div>
          <div class="gmail_default"><font face="monospace, monospace"># </font></div>
          <div class="gmail_default"><font face="monospace, monospace">#
              $Formiga</font></div>
          <div class="gmail_default"><font face="monospace, monospace">#
                      Group.1 Injuria  Area</font></div>
          <div class="gmail_default"><font face="monospace, monospace">#
              1    Abre Campo       0 12.65</font></div>
          <div class="gmail_default"><font face="monospace, monospace">#
              2       Vitoria       0  9.70</font></div>
          <div class="gmail_default"><font face="monospace, monospace">#
              3 Volta Redonda       0  4.75</font></div>
          <div class="gmail_default"><font face="monospace, monospace">###
              </code></font></div>
        </div>
      </div>
      <div class="gmail_extra"><br clear="all">
        <div>
          <div class="gmail_signature">
            <div dir="ltr">
              <div>
                <div dir="ltr">
                  <div>
                    <div dir="ltr"><font style="font-size:small"
                        face="arial, helvetica, sans-serif">
                        <div style="font-family:'trebuchet
                          ms',sans-serif;display:inline">​</div>
                        ================================================<br>
                        Éder Comunello</font>
                      <div style="font-size:small"><span
                          style="font-family:arial,helvetica,sans-serif">PhD
                          Student in Agricultural Systems
                          Engineering (USP/Esalq)</span><br>
                      </div>
                      <div><span style="font-size:small">Brazilian
                          Agricultural Research Corporation (</span><font
                          style="font-size:small" face="arial,
                          helvetica, sans-serif">Embrapa)</font>
                        <div style="font-size:small"><font face="arial,
                            helvetica, sans-serif">Dourados, MS, Brazil
                            [</font>22 16.5'S, 54 49.0'W<span
                            style="font-family:arial,helvetica,sans-serif">]</span></div>
                        <div>
                          <div><br>
                          </div>
                          <div><br>
                          </div>
                        </div>
                        <div style="font-size:small"><br>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <br>
        <div class="gmail_quote">Em 21 de janeiro de 2016 11:41, Manoel
          Galdino <span dir="ltr"><<a moz-do-not-send="true"
              href="mailto:mcz.fea@gmail.com" target="_blank">mcz.fea@gmail.com</a>></span>
          escreveu:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div dir="ltr">
              <div>
                <div>
                  <div>Eu não entendi o que você quer fazer. No seu
                    exemplo, o primeiro elemento é besouro, mas você
                    retornou barata.<br>
                    <br>
                  </div>
                  <div>Os valores de talhao e area nnao parecem bater
                    com os dados do seu exemplo. Como para Formiga o
                    talhão de volta redonda seria 73, se na base
                    original os valores são 74 e 15?<br>
                  </div>
                  <br>
                </div>
                <div>Abc<br>
                </div>
                <div>Manoel<br>
                  <br>
                  > tableFE<br>
                  <br>
                       Bichos Talhao       Projeto Injuria Area<br>
                    Besouros     73    Abre Campo      25  0.0<br>
                      Barata     15 Volta Redonda     100  0.0<br>
                    Formiga     74       Vitoria       0 12.5<br>
                     Barata     75    Abre Campo      25  0.0<br>
                    Formiga     15 Volta Redonda       0  7.5<br>
                    Besouros     15       Vitoria     100  0.0<br>
                     Formiga     15    Abre Campo       0  1.5<br>
                    Besouros     73 Volta Redonda      50  0.0<br>
                     Barata     15       Vitoria      25  0.0<br>
                    Formiga     15    Abre Campo       0 23.8<br>
                     Barata     73 Volta Redonda      25  0.0<br>
                    Formiga     15       Vitoria       0  5.3<br>
                   Besouros     73    Abre Campo      25  0.0<br>
                    Formiga     74 Volta Redonda       0  2.0<br>
                    Formiga     74       Vitoria       0 11.3<br>
                </div>
                <br>
              </div>
              Mas seus resultados não têm a média<br>
              <div>
                <div>
                  <div class="gmail_extra">
                    <div>
                      <div class="h5"><br>
                        <div class="gmail_quote">2016-01-21 11:07
                          GMT-02:00 ASANTOS <span dir="ltr"><<a
                              moz-do-not-send="true"
                              href="mailto:alexandresantosbr@yahoo.com.br"
                              target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:alexandresantosbr@yahoo.com.br">alexandresantosbr@yahoo.com.br</a></a>></span>:<br>
                          <blockquote class="gmail_quote"
                            style="margin:0px 0px 0px
                            0.8ex;border-left:1px solid
                            rgb(204,204,204);padding-left:1ex">Caros
                            listeiros,<br>
                            <br>
                            <br>
                               Estou tentando criar uma função aggPestFE
                            que para uma primeira variável se for
                            "Formiga", vai tirar a media da coluna 5,
                            mas se for "Besouros" ou "Barata" vai tira a
                            média da coluna 4. Sendo que quero o
                            resultado dado em forma de list, ficando o
                            meu resultado:<br>
                            <br>
                            [[1]]<br>
                            [1] "Barata"<br>
                            <br>
                            [[1]][[3]]<br>
                                    Projeto Talhao Injuria(%)<br>
                            1    Abre Campo     15        25<br>
                            2 Volta Redonda     73        0<br>
                            3       Vitoria     74        50<br>
                            <br>
                            <br>
                            [[2]]<br>
                            [1] "Besouros"<br>
                            <br>
                            [[1]][[3]]<br>
                                    Projeto Talhao Injuria(%)<br>
                            1    Abre Campo     15        0<br>
                            2 Volta Redonda     73        25<br>
                            3       Vitoria     74        50<br>
                            <br>
                            [[2]]<br>
                            [1] "Formiga"<br>
                            <br>
                            [[1]][[3]]<br>
                                    Projeto Talhao   Area  (m2)<br>
                            1    Abre Campo     15        12.5<br>
                            2 Volta Redonda     73        1.5<br>
                            3       Vitoria     74        23.8<br>
                            <br>
                            <br>
                                       Para isso estou tentando:<br>
                            <br>
                            <br>
                            ##Dados artificiais<br>
                            <br>
Bichos<-c("Besouros","Barata","Formiga","Barata","Formiga","Besouros","Formiga",<br>
"Besouros","Barata","Formiga","Barata","Formiga","Besouros","Formiga","Formiga")<br>
                            <br>
Talhao<-c(73,15,74,75,15,15,15,73,15,15,73,15,73,74,74)<br>
                            <br>
                            <br>
                            Projeto<-c("Abre Campo", "Volta
                            Redonda","Vitoria","Abre Campo", "Volta
                            Redonda",<br>
                            "Vitoria","Abre Campo", "Volta
                            Redonda","Vitoria","Abre Campo", "Volta
                            Redonda",<br>
                            "Vitoria","Abre Campo", "Volta
                            Redonda","Vitoria")<br>
                            <br>
Injuria<-c(25,100,0,25,0,100,0,50,25,0,25,0,25,0,0)<br>
                            <br>
                            <br>
                            <br>
Area<-c(0,0,12.5,0,7.5,0,1.5,0,0,23.8,0,5.3,0,2.0,11.3)<br>
                            <br>
                            <br>
                            tableFE<-data.frame(Bichos, Talhao,
                            Projeto, Injuria, Area) ## Banco de dados
                            criado<br>
                            <br>
                            <br>
                            ##Função<br>
                            <br>
                            aggPestFE<-function(x, db=tableFE){<br>
                            <br>
                            <br>
                            mylist <- list()<br>
                            <br>
                            <br>
                            <br>
                            <br>
                                 if (tableFE[,1] != "Formigas") {<br>
                            <br>
                                    for (i in length(tableFE[,1])){<br>
                            <br>
                                   
                            GP_FE2<-tableFE[tableFE[,1]==tableFE[i],]<br>
                                    aggdata <-aggregate(GP_FE2[,4],
                            list(GP_FE2[,3],GP_FE2[,2]), mean)<br>
                            colnames(aggdata)<-c("Regional","Projeto","Talhão","Injúria
                            média (%)")<br>
                                    tmp <- list(aggdata)<br>
                                    mylist[NPRAGS[i]] <- tmp<br>
                                    result<-mylist<br>
                                    return(result)<br>
                                    }<br>
                            <br>
                            <br>
                                 else if (tableFE[,1] == "Formigas") {<br>
                            <br>
                                    GP_FE2<-[tableFE[,1]<br>
                                    aggdata <-aggregate(GP_FE2[,5],
                            list(GP_FE2[,3],GP_FE2[,2]), mean)<br>
                            colnames(aggdata)<-c("Regional","Projeto","Talhão","Injúria
                            média (%)")<br>
                                    tmp <- list(aggdata)<br>
                                    mylist[NPRAGS[i]] <- tmp<br>
                                    result<-mylist<br>
                                    return(result)<br>
                                    }<br>
                                    }<br>
                            <br>
                            RES<-list(result,aggdata3)<br>
                            result<-RES<br>
                            return(result)<br>
                            }<br>
                            <br>
                            <br>
                            #Teste<br>
                            aggPestFE(tableFE)<br>
                            #<br>
                            <br>
                               Sem sucesso, alguém poderia me ajudar?<br>
                            <br>
                            Obrigado e abraços,<br>
                            <br>
                            <br>
                            <br>
                            <br>
                            <br>
                            <br>
                            -- <br>
======================================================================<br>
                            Alexandre dos Santos<br>
                            Proteção Florestal<br>
                            IFMT - Instituto Federal de Educação,
                            Ciência e Tecnologia de Mato Grosso<br>
                            Campus Cáceres<br>
                            Caixa Postal 244<br>
                            Avenida dos Ramires, s/n<br>
                            Bairro: Distrito Industrial<br>
                            Cáceres - MT                      CEP:
                            78.200-000<br>
                            Fone: <a moz-do-not-send="true"
                              href="tel:%28%2B55%29%2065%208132-8112"
                              value="+556581328112" target="_blank">(+55)
                              65 8132-8112</a> (TIM)   <a
                              moz-do-not-send="true"
                              href="tel:%28%2B55%29%2065%209686-6970"
                              value="+556596866970" target="_blank">(+55)
                              65 9686-6970</a> (VIVO)<br>
                            <a moz-do-not-send="true"
                              href="mailto:e-mails%3Aalexandresantosbr@yahoo.com.br"
                              target="_blank">e-mails:alexandresantosbr@yahoo.com.br</a><br>
                                    <a moz-do-not-send="true"
                              href="mailto:alexandre.santos@cas.ifmt.edu.br"
                              target="_blank">alexandre.santos@cas.ifmt.edu.br</a><br>
                            Lattes: <a moz-do-not-send="true"
                              href="http://lattes.cnpq.br/1360403201088680"
                              rel="noreferrer" target="_blank">http://lattes.cnpq.br/1360403201088680</a><br>
                            OrcID: <a moz-do-not-send="true"
                              href="http://orcid.org/0000-0001-8232-6722"
                              rel="noreferrer" target="_blank">orcid.org/0000-0001-8232-6722</a><br>
                            Researchgate: <a moz-do-not-send="true"
                              href="https://www.researchgate.net/profile/Alexandre_Santos10"
                              rel="noreferrer" target="_blank">https://www.researchgate.net/profile/Alexandre_Santos10</a><br>
                            LinkedIn: <a moz-do-not-send="true"
                              href="https://br.linkedin.com/in/alexandre-dos-santos-87961635"
                              rel="noreferrer" target="_blank">https://br.linkedin.com/in/alexandre-dos-santos-87961635</a><br>
======================================================================<br>
                            <br>
_______________________________________________<br>
                            R-br mailing list<br>
                            <a moz-do-not-send="true"
                              href="mailto:R-br@listas.c3sl.ufpr.br"
                              target="_blank">R-br@listas.c3sl.ufpr.br</a><br>
                            <a moz-do-not-send="true"
                              href="https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br"
                              rel="noreferrer" target="_blank">https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br</a><br>
                            Leia o guia de postagem (<a
                              moz-do-not-send="true"
                              href="http://www.leg.ufpr.br/r-br-guia"
                              rel="noreferrer" target="_blank"><a class="moz-txt-link-freetext" href="http://www.leg.ufpr.br/r-br-guia">http://www.leg.ufpr.br/r-br-guia</a></a>)
                            e fornea cdigo mnimo reproduzvel.</blockquote>
                        </div>
                        <br>
                        <br clear="all">
                        <br>
                      </div>
                    </div>
                    <span class="HOEnZb"><font color="#888888">-- <br>
                        <div>Manoel Galdino<br>
                          <a moz-do-not-send="true"
                            href="https://sites.google.com/site/galdinomcz/"
                            target="_blank">https://sites.google.com/site/galdinomcz/</a><br>
                        </div>
                      </font></span></div>
                </div>
              </div>
            </div>
            <br>
            _______________________________________________<br>
            R-br mailing list<br>
            <a moz-do-not-send="true"
              href="mailto:R-br@listas.c3sl.ufpr.br">R-br@listas.c3sl.ufpr.br</a><br>
            <a moz-do-not-send="true"
              href="https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br"
              rel="noreferrer" target="_blank">https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br</a><br>
            Leia o guia de postagem (<a moz-do-not-send="true"
              href="http://www.leg.ufpr.br/r-br-guia" rel="noreferrer"
              target="_blank">http://www.leg.ufpr.br/r-br-guia</a>) e
            forneça código mínimo reproduzível.<br>
          </blockquote>
        </div>
        <br>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
R-br mailing list
<a class="moz-txt-link-abbreviated" href="mailto:R-br@listas.c3sl.ufpr.br">R-br@listas.c3sl.ufpr.br</a>
<a class="moz-txt-link-freetext" href="https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br">https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br</a>
Leia o guia de postagem (<a class="moz-txt-link-freetext" href="http://www.leg.ufpr.br/r-br-guia">http://www.leg.ufpr.br/r-br-guia</a>) e forne�a c�digo m�nimo reproduz�vel.</pre>
    </blockquote>
    <br>
  </body>
</html>