<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif">Senhores, bom dia!</div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">Segue uma ideia...</div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">### <code r</div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style=""><div class="gmail_default"><font face="verdana, sans-serif">individuo <-list(c(8,9,6,0,8,7,8,0,9,2,6,6,0,7,8,2,8,1,3,6,3,2,3,2,0,6,3,3,8,7))</font></div><div class="gmail_default"><font face="verdana, sans-serif">individuo[[1]]</font></div><div class="gmail_default"><font face="verdana, sans-serif"><br></font></div><div class="gmail_default"><font face="verdana, sans-serif"># Pra contar o número de sequências me pareceu mais fácil...</font></div><div class="gmail_default"><font face="verdana, sans-serif">res <- data.frame(unclass(rle(individuo[[1]]<4))); res</font></div><div class="gmail_default"><font face="verdana, sans-serif">sum(res$len[res$values==T]%/%2) # 4</font></div><div class="gmail_default"><font face="verdana, sans-serif"><br></font></div><div class="gmail_default"><font face="verdana, sans-serif"># Pra apresentar as sequências, ainda é possível melhorar...</font></div><div class="gmail_default"><font face="verdana, sans-serif">pos <- NULL</font></div><div class="gmail_default"><font face="verdana, sans-serif">for (i in 1:nrow(res)) {</font></div><div class="gmail_default"><font face="verdana, sans-serif"> if (res$values[i]) tmp=rep(1:2,len=res$lengths[i]) </font></div><div class="gmail_default"><font face="verdana, sans-serif"> else tmp=rep(0, len=res$lengths[i])</font></div><div class="gmail_default"><font face="verdana, sans-serif"> pos <- c(pos, tmp)</font></div><div class="gmail_default"><font face="verdana, sans-serif">}</font></div><div class="gmail_default"><font face="verdana, sans-serif"><br></font></div><div class="gmail_default"><font face="verdana, sans-serif">pos2 <- NULL</font></div><div class="gmail_default"><font face="verdana, sans-serif">for (i in which(pos==2)) {tmp <- c(i-1, i); pos2 <- c(pos2, tmp)}</font></div><div class="gmail_default"><font face="verdana, sans-serif">individuo[[1]][pos2] # [1] 1 3 3 2 3 2 3 3</font></div><div class="gmail_default"><font face="verdana, sans-serif"><br></font></div><div class="gmail_default"><font face="verdana, sans-serif">### </code></font></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"><div><div dir="ltr"><font face="arial, helvetica, sans-serif" style="font-size:small"><div style="font-family:'trebuchet ms',sans-serif;display:inline"></div></font><font face="arial, helvetica, sans-serif" style="font-size:12.8px"><span style="font-size:small">================================================</span><br>Éder Comunello</font><div style="font-size:12.8px"><span style="font-family:arial,helvetica,sans-serif">Agronomist (UEM), MSc in Environ. Sciences (UEM)</span><font face="arial, helvetica, sans-serif"><br></font></div><div style="font-size:12.8px"><div style="font-size:small"><span style="font-family:arial,helvetica,sans-serif">DSc in Agricultural Systems Engineering (USP/Esalq)</span><br></div><div><span style="font-size:small">Brazilian Agricultural Research Corporation (</span><font face="arial, helvetica, sans-serif" style="font-size:small">Embrapa)</font></div><div><div><font face="arial, helvetica, sans-serif" style="font-size:small">Dourados, MS, Brazil </font><font face="arial, helvetica, sans-serif" size="2">|<O>|</font></div><div style="font-size:small"><span style="font-family:arial,helvetica,sans-serif">================================================</span><br></div></div></div><div style="font-size:small"><font face="arial, helvetica, sans-serif">GEO, </font>-22.2752, -54.8182, 408m<span style="font-family:arial,helvetica,sans-serif"><br></span></div><div style="font-size:12.8px"><span style="font-size:small;font-family:arial,helvetica,sans-serif">UTC-04:00 / DST: UTC-03:00</span></div><div><div><div><br></div><div><br></div></div><div style="font-size:small"><br></div></div></div></div></div></div></div></div></div></div></div>
<br><div class="gmail_quote">Em 14 de maio de 2016 16:10, Fernando Gama <span dir="ltr"><<a href="mailto:f.fabiogama88@gmail.com" target="_blank">f.fabiogama88@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><font color="#0b5394" face="arial narrow, sans-serif">Oi Augusto obrigado por responder.,</font></div><div><font color="#0b5394" face="arial narrow, sans-serif"><br></font></div><div><font color="#0b5394" face="arial narrow, sans-serif">Correção quando escrevi: </font><span style="color:rgb(11,83,148);font-family:'arial narrow',sans-serif;font-size:12.8px">A</span><font color="#ff0000"><span style="font-family:'arial narrow',sans-serif;font-size:12.8px">i ficaria assim: [8 9 6</span><b style="font-family:'arial narrow',sans-serif;font-size:12.8px"> 0</b><span style="font-family:'arial narrow',sans-serif;font-size:12.8px"> 8 7 8 </span><b style="font-family:'arial narrow',sans-serif;font-size:12.8px">0</b><span style="font-family:'arial narrow',sans-serif;font-size:12.8px"> 9 </span><b style="font-family:'arial narrow',sans-serif;font-size:12.8px">2</b><span style="font-family:'arial narrow',sans-serif;font-size:12.8px"> 6 6 </span><b style="font-family:'arial narrow',sans-serif;font-size:12.8px">0</b><span style="font-family:'arial narrow',sans-serif;font-size:12.8px"> 7 8 </span><b style="font-family:'arial narrow',sans-serif;font-size:12.8px">2 </b><span style="font-family:'arial narrow',sans-serif;font-size:12.8px">8 </span><u><b style="font-family:'arial narrow',sans-serif;font-size:12.8px">1 </b><span style="font-family:'arial narrow',sans-serif;font-size:12.8px"><b>3</b></span></u><span style="font-family:'arial narrow',sans-serif;font-size:12.8px"> 6 </span><b style="font-family:'arial narrow',sans-serif;font-size:12.8px">3 <u>2</u></b><span style="text-decoration:underline;font-family:'arial narrow',sans-serif;font-size:12.8px"> </span><b style="font-family:'arial narrow',sans-serif;font-size:12.8px"><u>3</u> </b><span style="text-decoration:underline;font-family:'arial narrow',sans-serif;font-size:12.8px"> </span><b style="text-decoration:underline;font-family:'arial narrow',sans-serif;font-size:12.8px">2</b><span style="text-decoration:underline;font-family:'arial narrow',sans-serif;font-size:12.8px"> </span><b style="text-decoration:underline;font-family:'arial narrow',sans-serif;font-size:12.8px">0</b><span style="font-family:'arial narrow',sans-serif;font-size:12.8px"> 6 </span><b style="font-family:'arial narrow',sans-serif;font-size:12.8px"><u>3 3</u></b><span style="font-family:'arial narrow',sans-serif;font-size:12.8px"> 8 7]*</span></font></div><div><span style="color:rgb(11,83,148);font-family:'arial narrow',sans-serif;font-size:12.8px"><br></span></div><div><span style="color:rgb(11,83,148);font-family:'arial narrow',sans-serif;font-size:12.8px">o output ficaria assim: </span><font color="#ff0000"><span style="font-family:'arial narrow',sans-serif;font-size:12.8px">[</span><b style="font-family:'arial narrow',sans-serif;font-size:12.8px">0</b><span style="font-family:'arial narrow',sans-serif;font-size:12.8px"> </span><b style="font-family:'arial narrow',sans-serif;font-size:12.8px">0</b><span style="font-family:'arial narrow',sans-serif;font-size:12.8px"> </span><b style="font-family:'arial narrow',sans-serif;font-size:12.8px">2</b><span style="font-family:'arial narrow',sans-serif;font-size:12.8px"> </span><b style="font-family:'arial narrow',sans-serif;font-size:12.8px">0</b><span style="font-family:'arial narrow',sans-serif;font-size:12.8px"> </span><b style="font-family:'arial narrow',sans-serif;font-size:12.8px">2</b><span style="font-family:'arial narrow',sans-serif;font-size:12.8px"> </span><b style="font-family:'arial narrow',sans-serif;font-size:12.8px">1 3</b><span style="font-family:'arial narrow',sans-serif;font-size:12.8px"> </span><b style="font-family:'arial narrow',sans-serif;font-size:12.8px">3 2</b><span style="font-family:'arial narrow',sans-serif;font-size:12.8px"> </span><b style="font-family:'arial narrow',sans-serif;font-size:12.8px">3</b><span style="font-family:'arial narrow',sans-serif;font-size:12.8px"> </span><b style="font-family:'arial narrow',sans-serif;font-size:12.8px">2</b><span style="font-family:'arial narrow',sans-serif;font-size:12.8px"> </span><b style="font-family:'arial narrow',sans-serif;font-size:12.8px">0</b><span style="font-family:'arial narrow',sans-serif;font-size:12.8px"> </span><b style="font-family:'arial narrow',sans-serif;font-size:12.8px">3 3</b><span style="font-family:'arial narrow',sans-serif;font-size:12.8px"> ] </span></font><span style="color:rgb(11,83,148);font-family:'arial narrow',sans-serif;font-size:12.8px">o retorno da sua função exemplo está correto Augusto, porém perdemos a referência de contagem. </span></div><div><span style="color:rgb(11,83,148);font-family:'arial narrow',sans-serif;font-size:12.8px"><br></span></div><div><span style="color:rgb(11,83,148);font-family:'arial narrow',sans-serif;font-size:12.8px">Eu só posso fazer a contagem do tamanho da cadeia quando vierem <b>em sequencia (marquei com underline ai em cima)</b>. Nesse caso, como o tamanho da cadeia = 2, Então eu irei contar da seguinte forma:</span></div><div><br></div><div><font color="#0b5394" face="arial narrow, sans-serif"><span style="font-size:12.8px">Em suma: </span></font></div><div><span style="color:rgb(255,0,0);font-family:'arial narrow',sans-serif;font-size:12.8px">Frequencia da cadeia = [3 3] + </span><span style="color:rgb(255,0,0);font-family:'arial narrow',sans-serif;font-size:12.8px">[</span><span style="color:rgb(255,0,0);font-family:'arial narrow',sans-serif;font-size:12.8px">2</span><span style="color:rgb(255,0,0);font-family:'arial narrow',sans-serif;font-size:12.8px"> </span><span style="color:rgb(255,0,0);font-family:'arial narrow',sans-serif;font-size:12.8px">0] + [2 3] + [1 3] = 4.</span></div><div><span style="color:rgb(255,0,0);font-family:'arial narrow',sans-serif;font-size:12.8px"><br></span></div><div><span style="font-family:'arial narrow',sans-serif;font-size:12.8px"><font color="#073763">Gostaria de ter esse retorno na função: Total=<b>4</b>.</font></span></div><div><span style="font-family:'arial narrow',sans-serif;font-size:12.8px"><font color="#073763"><br></font></span></div><div><font color="#073763" face="arial narrow, sans-serif"><span style="font-size:12.8px">Obrigado.</span></font></div><div class="gmail_extra"><div><div class="h5"><br><div class="gmail_quote">Em 14 de maio de 2016 16:03, Augusto Ribas <span dir="ltr"><<a href="mailto:ribas.aca@gmail.com" target="_blank">ribas.aca@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>Eu não entendi muito bem o problema, mas daria para definir uma função, e usar ela no lapply para toda a sua lista.<br></div>Veja se esse exemplo ajuda.<br><div><div><div><br>###Gerando dados de exemplo<br>set.seed(123)<br>lista<-list()<br>j<-1<br>for(i in sample(1:10,20,replace=T)){<br> lista[[j]]<-sample(1:10,i,replace=T)<br> j<-j+1<br>}<br>###O exemplo<br>lista<br><br>###Faça uma função que retorna o que você quer<br>funcao<-function(x){<br> if(length(x)>2 && sum(x<4)>=1){<br> return(x[x<4])<br> }else{<br> return(NA)<br> }<br>}<br> <br>###Exemplo de uso<br>funcao(lista[[1]])<br>funcao(lista[[2]])<br><br>###Para uma lista, da para usar lapply<br>lapply(lista,funcao)<br></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div>Em 14 de maio de 2016 14:35, Fernando Gama <span dir="ltr"><<a href="mailto:f.fabiogama88@gmail.com" target="_blank">f.fabiogama88@gmail.com</a>></span> escreveu:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr"><div style="font-family:'arial narrow',sans-serif;color:rgb(11,83,148)">Eu tenho uma lista com os seguintes numeros:</div><div style="font-family:'arial narrow',sans-serif;color:rgb(11,83,148)"><br></div><div><div style="font-family:'arial narrow',sans-serif;color:rgb(11,83,148)">individuo[[1]]= [8 9 6 0 8 7 8 0 9 2 6 6 0 7 8 2 8 1 3 6 3 2 3 2 0 6 3 3 8 7]</div><div style="font-family:'arial narrow',sans-serif;color:rgb(11,83,148)"><br></div><div style="font-family:'arial narrow',sans-serif;color:rgb(11,83,148)">Gostaria de detectar (realizar a contagem de sequencias dada um tamanho de cadeia).</div><div style="font-family:'arial narrow',sans-serif;color:rgb(11,83,148)">Baseado nos seguintes filtros:</div><div style="font-family:'arial narrow',sans-serif;color:rgb(11,83,148)"><br></div><div style="font-family:'arial narrow',sans-serif;color:rgb(11,83,148)">1) tamanho da cadeia = 2 </div><div style="font-family:'arial narrow',sans-serif;color:rgb(11,83,148)">2) pegar somente os valores iguais ou abaixo de 4</div><div style="font-family:'arial narrow',sans-serif;color:rgb(11,83,148)"><br></div><div style="font-family:'arial narrow',sans-serif;color:rgb(11,83,148)">Ai ficaria assim: [8 9 6<b> 0</b> 8 7 8 <b>0</b> 9 <b>2</b> 6 6 <b>0</b> 7 8 <b>2 </b>8 <b>1 3</b> 6 <b>3 2</b> <b>3</b> <b>2</b> <b>0</b> 6 <b>3 3</b> 8 7]<br></div><div style="font-family:'arial narrow',sans-serif;color:rgb(11,83,148)"><br></div><div style="font-family:'arial narrow',sans-serif;color:rgb(11,83,148)">Tentei fazer começar com o which() para pegar as posicoes em sequencia:</div><div style="font-family:'arial narrow',sans-serif;color:rgb(11,83,148)">which(individuo[[1]]<=4) e com rle(individuo[[1]]), este ultimo só funciona para sequencias de numeros iguais.</div><br></div><div><div style="font-family:'arial narrow',sans-serif;color:rgb(11,83,148)">Porém, ainda nao encontrei uma maneira de detectar sequencias baseados no tamanho da cadeia. Como setei lá em cima(tamanho da cadeia = 2), então o output seria essas 4 sequencias: </div><div style="font-family:'arial narrow',sans-serif;color:rgb(11,83,148)">[<b style="text-decoration:underline">1 3</b> <b>3 2 </b> <b><u>3 2</u></b> <b>3 3</b>]. Teria portanto, 8 numeros com 4 sequencias.</div><div style="font-family:'arial narrow',sans-serif;color:rgb(11,83,148)"><br></div><div style="font-family:'arial narrow',sans-serif;color:rgb(11,83,148)">Alguem pode ajudar? :/</div><div style="font-family:'arial narrow',sans-serif;color:rgb(11,83,148)"><br></div><div style="font-family:'arial narrow',sans-serif;color:rgb(11,83,148)"><br></div><div style="font-family:'arial narrow',sans-serif;color:rgb(11,83,148)"></div><span><font color="#888888"><br></font></span></div><span><font color="#888888"><div><br></div>-- <br><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div style="text-align:center"><font face="arial narrow, sans-serif" color="#0c343d" size="2">Att,</font></div><div style="text-align:center"><div style="font-family:'arial narrow',sans-serif;color:rgb(11,83,148)">Fernando.</div><br></div></div></div></div></div>
</font></span></div>
<br></div></div>_______________________________________________<br>
R-br mailing list<br>
<a href="mailto:R-br@listas.c3sl.ufpr.br" target="_blank">R-br@listas.c3sl.ufpr.br</a><br>
<a 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 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.<span><font color="#888888"><br></font></span></blockquote></div><span><font color="#888888"><br><br clear="all"><br>-- <br><div><div dir="ltr"><div>Grato<br>Augusto C. A. Ribas</div>
<div> </div>
<div>Site Pessoal: <a href="http://recologia.com.br/" target="_blank">http://recologia.com.br/</a><a href="http://augustoribas.heliohost.org" target="_blank"></a></div><div>Github: <a href="https://github.com/Squiercg" target="_blank">https://github.com/Squiercg</a></div>
<div>Lattes: <a href="http://lattes.cnpq.br/7355685961127056" target="_blank">http://lattes.cnpq.br/7355685961127056</a><br></div></div></div>
</font></span></div>
<br>_______________________________________________<br>
R-br mailing list<br>
<a href="mailto:R-br@listas.c3sl.ufpr.br" target="_blank">R-br@listas.c3sl.ufpr.br</a><br>
<a 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 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><br clear="all"><div><br></div>-- <br></div></div><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div style="text-align:center"><font color="#0c343d" face="arial narrow, sans-serif" size="2">Att,</font></div><div style="text-align:center"><font color="#0c343d" face="arial narrow, sans-serif" size="2"><br></font></div><div style="text-align:center"><font color="#0c343d" face="arial narrow, sans-serif" size="2">Fernando Gama da Mata</font></div><div style="text-align:center"><br></div></div></div></div></div>
</div></div>
<br>_______________________________________________<br>
R-br mailing list<br>
<a href="mailto:R-br@listas.c3sl.ufpr.br">R-br@listas.c3sl.ufpr.br</a><br>
<a 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 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></div>