<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Rubem,<div><br></div><div>Acho que fui infeliz ao exemplificar o meu problema,</div><div>na verdade nos meus dados reais estou obtendo os seguinte erro:</div><div><br></div><div><div>Error in attributes(out) <- attributes(col) : </div><div>  'names' attribute [2510] must be the same length as the vector [5]</div></div><div><br></div><div>Já verifiquei na internet todas as tentativas:</div><div><br></div><div><a href="http://stackoverflow.com/questions/18854934/ddply-error-error-in-attributesout-attributescol-names-attribute-mus">http://stackoverflow.com/questions/18854934/ddply-error-error-in-attributesout-attributescol-names-attribute-mus</a></div><div><a href="http://stackoverflow.com/questions/14153092/meaning-of-ddply-error-names-attribute-9-must-be-the-same-length-as-the-vec">http://stackoverflow.com/questions/14153092/meaning-of-ddply-error-names-attribute-9-must-be-the-same-length-as-the-vec</a></div><div><a href="http://searchinsleep.blogspot.de/2013/05/plyr-18-problem-updated.html">http://searchinsleep.blogspot.de/2013/05/plyr-18-problem-updated.html</a></div><div><br></div><div>Nenhuma deu certo… e pelo que vi… no terceiro link é parece ter observado um problema do pacote plyr 1.8…</div><div><br></div><div>Alguém sugere outra alternativa?</div><div><br></div><div><br></div><div><div>Em 25/02/2014, à(s) 17:49, Rubem Kaipper Ceratti <<a href="mailto:rubem_ceratti@yahoo.com.br">rubem_ceratti@yahoo.com.br</a>> escreveu:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><div style="background-color: rgb(255, 255, 255); font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 10pt;"><div><span>Apenas tire a parte '<span style="font-style: italic;">matrix.x$'</span> e deve funcionar:</span></div><div style="font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;"><span><br></span></div><div style="background-color: transparent;"><span><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif;">R2 <- ddply(matrix.x, 'seq', transform, var=funcao.x(var1))</span><br></span></div><div><br></div><div style="font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;"><br></div><div style="font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;"><br></div>  <div style="font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 10pt;"> <div style="font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12pt;"> <div dir="ltr"> <hr size="1">  <font size="2" face="Arial"> <b><span style="font-weight:bold;">De:</span></b> Tropidurus Torquatus <<a href="mailto:t.torquatus@gmail.com">t.torquatus@gmail.com</a>><br> <b><span style="font-weight: bold;">Para:</span></b> <a href="mailto:r-br@listas.c3sl.ufpr.br">r-br@listas.c3sl.ufpr.br</a> <br> <b><span style="font-weight: bold;">Enviadas:</span></b> Terça-feira, 25 de Fevereiro de 2014 12:41<br> <b><span style="font-weight: bold;">Assunto:</span></b> [R-br] Família ply<br> </font> </div> <div class="y_msg_container"><br><div id="yiv4458045722"><div>Caros
 R-users</div><div><br></div><div>Dada uma matrix qualquer:</div><div><br></div><div><span style="background-color:rgb(0, 0, 0);"><font color="#29f914" face="Andale Mono">seq = c("a","a","a","a","a","a","b","b","b","b","b","c","c","c","c","c","c","c","c","c","c","c","c","c”)</font></span></div><div><div style="margin: 0px; font-family: 'Andale Mono'; color: rgb(41, 249, 20); background-color: rgb(0, 0, 0);">var1 = c(1,2,3,4,5,6,0,1,2,3,4,0,1,2,3,4,5,6,7,8,9,10,11,12)</div></div><div><div style="margin: 0px; font-family: 'Andale Mono'; color: rgb(41, 249, 20); background-color: rgb(0, 0, 0);">matrix.x = data.frame(seq,var1)</div></div><div><br></div><div>funcao.x = function(x,d=1,T=3)</div><div><span class="yiv4458045722Apple-tab-span" style="white-space:pre;">         </span>{</div><div><span class="yiv4458045722Apple-tab-span" style="white-space:pre;">                      </span>i = exp ( ( -x ) / ( d * T ) )</div><div><span class="yiv4458045722Apple-tab-span" style="white-space:pre;">                 </span>net = sum (i)</div><div><span class="yiv4458045722Apple-tab-span" style="white-space:pre;">                  </span>resultado = 100 * ( i / net )  </div><div></div><div><span class="yiv4458045722Apple-tab-span" style="white-space:pre;">                       </span>return (resultado)</div><div><span class="yiv4458045722Apple-tab-span" style="white-space:pre;">             </span>}</div><div><br></div><div>Preciso aplicar a função dentro de cada subgrupo (seq) da matrix.x e criar ou um novo data.frame ou uma nova linha da matrix.x.</div><div>Tentei utilizar o comando ddply do pacote, com o comando abaixo, não sei se essa seria a melhor forma, mas mesmo assim não estou conseguindo:</div><div>
        
        
        <div style="margin-bottom:0.71cm;">library(“plyr”) </div></div><div><br></div><div><br></div><div><div style="margin: 0px; font-family: 'Andale Mono'; color: rgb(41, 249, 20); background-color: rgb(0, 0, 0); position: static; z-index: auto;">R2 <- ddply(matrix.x, 'seq', transform, var=funcao.x(var1))</div><div style="margin: 0px; font-family: 'Andale Mono'; color: rgb(0, 249, 0); background-color: rgb(0, 0, 0);">Error in data.frame(list(seq = c(2L, 2L, 2L, 2L, 2L), var1 = c(0, 1, 2,  : arguments imply differing number of rows: 5, 24</div></div><div><br></div><div><br></div><div>Na verdade essa formula deveria dar um valor para cada linha… não sei se escolhi a função correta para o que necessito, alguém poderia me mostrar um caminho a seguir?</div><div><br></div><div>No mais agradeço,</div><div><br></div><div>Thales Siqueira</div><div><br></div><div><br></div></div><br>_______________________________________________<br>R-br mailing list<br><a ymailto="mailto:R-br@listas.c3sl.ufpr.br" 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" 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" target="_blank">http://www.leg.ufpr.br/r-br-guia</a>) e forneça código mínimo reproduzível.<br><br></div> </div> </div>  </div></div>_______________________________________________<br>R-br mailing list<br><a href="mailto:R-br@listas.c3sl.ufpr.br">R-br@listas.c3sl.ufpr.br</a><br>https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br<br>Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia) e forneça código mínimo reproduzível.</blockquote></div><br></body></html>