<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'><div>Oi pessoal,</div><div>Estou com uma dificuldade de efetivar um 'if' dentro do 'else'.</div><div>É possível fazer isso né? </div><div>Estou trabalhando com uma técnica de agrupamento baseado na "transferência de entropia mútua" que é a matriz do exemplo.</div><div>Grifei o problema em amarelo.</div><div>Se puderem me ajudar.</div><div>Agradecido,</div><div>Arthur.</div><div><br></div><div><br></div><div><br></div><div>#Exemplo:</div><div><br></div><div>col1=c(1,0.45,0.25,0.18,0.14,0.22,0.26,0.41)</div><div>col2=c(0.54,1,0.50,0.15,0.15,0.3,0.27,0.28)</div><div>col3=c(0.2,0.52,1,0.21,0.17,0.5,0.22,0.26)</div><div>col4=c(0.13,0.17,0.28,1,0.4,0.22,0.5,0.16)</div><div>col5=c(0.12,0.15,0.15,0.42,1,0.19,0.31,0.14)</div><div>col6=c(0.2,0.32,0.49,0.25,0.21,1,0.23,0.2)</div><div>col7=c(0.21,0.25,0.19,0.48,0.29,0.19,1,0.21)</div><div>col8=c(0.47,0.32,0.29,0.22,0.15,0.23,0.2,1)</div><div><br></div><div>dados=cbind(col1,col2,col3,col4,col5,col6,col7,col8) # matrix DIT (direcional information transfer)</div><div><br></div><div><span style="font-size: 12pt;">#Prática</span></div><div><br></div><div>Dit=dados</div><div>threshold=0.35</div><div>grupos=list(0,0,0,0,0,0,0,0) # 8 pois é o máximo número de grupos</div><div><br></div><div>#lógica 1</div><div>for (i in 1:ncol(dados))</div><div><span class="Apple-tab-span" style="white-space:pre">   </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">            </span>for (j in i:ncol(dados))</div><div><span class="Apple-tab-span" style="white-space:pre">             </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">            </span>if ((Dit[i,j]>=threshold && Dit[j,i]>=threshold) && Dit[i,j]!=1)   #condição para agrupar --> i e j > thresold</div><div><span class="Apple-tab-span" style="white-space:pre">                      </span></div><div><span class="Apple-tab-span" style="white-space:pre">                     </span>for (k in 1:i)<span class="Apple-tab-span" style="white-space:pre">                                                              </span>#verificar se i ou j estão em algum grupo anterior<span class="Apple-tab-span" style="white-space:pre">  </span></div><div><span class="Apple-tab-span" style="white-space:pre">                     </span>{ </div><div><span class="Apple-tab-span" style="white-space:pre">                      </span>if (sum(grupos[[k]])==i | sum(grupos[[k]])==j) {grupos[[k]]=cbind(grupos[[k]],i,j)} </div><div><span class="Apple-tab-span" style="white-space:pre">                    </span></div><div><span class="Apple-tab-span" style="white-space:pre">                     </span><span style="background-color: rgb(255, 255, 0);">else {(if (grupos[[k]]==0)  {grupos[[k]]=c(i,j)})}</span><span class="Apple-tab-span" style="white-space:pre">                                              </span>##Problema: fazer if dentro do else</div><div><span class="Apple-tab-span" style="white-space:pre">                  </span>} </div><div><span class="Apple-tab-span" style="white-space:pre">      </span></div><div><span class="Apple-tab-span" style="white-space:pre">             </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">    </span>}</div>                                        </div></body>
</html>