<div dir="ltr">Boa tarde colegas listeiros, como vão?<div><br></div><div>Tenho um problema e estou com certa dificuldade em resolver de forma prática. Meu conjunto de dados é o seguinte:</div><div><table border="0" cellpadding="0" cellspacing="0" width="352" style="border-collapse:collapse;width:264pt">
<colgroup><col width="64" style="width:48pt">
<col width="74" style="width:56pt">
<col width="75" style="width:56pt">
<col width="75" style="width:56pt">
<col width="64" style="width:48pt">
</colgroup><tbody><tr height="20" style="height:15pt">
<td height="20" width="64" style="height:15pt;width:48pt;padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">local</td>
<td width="74" style="width:56pt;padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">frequencia</td>
<td width="75" style="width:56pt;padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">data</td>
<td class="gmail-xl64" width="75" style="width:56pt;padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">quantidade</td>
<td width="64" style="width:48pt;padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap"><b>valido</b></td>
</tr>
<tr height="20" style="height:15pt">
<td height="20" style="height:15pt;padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">A</td>
<td align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">2</td>
<td class="gmail-xl63" align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">13/05/2015</td>
<td class="gmail-xl64" align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">500,00</td>
<td align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap"><b>0</b></td>
</tr>
<tr height="20" style="height:15pt">
<td height="20" style="height:15pt;padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">A</td>
<td align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">2</td>
<td class="gmail-xl63" align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">13/05/2015</td>
<td class="gmail-xl64" align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">700,00</td>
<td align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap"><b>1</b></td>
</tr>
<tr height="20" style="height:15pt">
<td height="20" style="height:15pt;padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">A</td>
<td align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">1</td>
<td class="gmail-xl63" align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">13/05/2015</td>
<td class="gmail-xl64" align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">700,00</td>
<td align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap"><b>0</b></td>
</tr>
<tr height="20" style="height:15pt">
<td height="20" style="height:15pt;padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">B</td>
<td align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">3</td>
<td class="gmail-xl63" align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">13/05/2015</td>
<td class="gmail-xl64" align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">400,00</td>
<td align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap"><b>1</b></td>
</tr>
<tr height="20" style="height:15pt">
<td height="20" style="height:15pt;padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">C</td>
<td align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">5</td>
<td class="gmail-xl63" align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">13/05/2015</td>
<td class="gmail-xl64" align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">300,00</td>
<td align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap"><b>0</b></td>
</tr>
<tr height="20" style="height:15pt">
<td height="20" style="height:15pt;padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">C</td>
<td align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">5</td>
<td class="gmail-xl63" align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">10/05/2015</td>
<td class="gmail-xl64" align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">400,00</td>
<td align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap"><b>0</b></td>
</tr>
<tr height="20" style="height:15pt">
<td height="20" style="height:15pt;padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">C</td>
<td align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">5</td>
<td class="gmail-xl63" align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">13/05/2016</td>
<td class="gmail-xl64" align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">400,00</td>
<td align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap"><b>1</b></td>
</tr>
<tr height="20" style="height:15pt">
<td height="20" style="height:15pt;padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">C</td>
<td align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">5</td>
<td class="gmail-xl63" align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">13/05/2015</td>
<td class="gmail-xl64" align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">900,00</td>
<td align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap"><b>1</b></td>
</tr>
<tr height="20" style="height:15pt">
<td height="20" style="height:15pt;padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">D</td>
<td align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">3</td>
<td class="gmail-xl63" align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">13/05/2015</td>
<td class="gmail-xl64" align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">550,00</td>
<td align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap"><b>0</b></td>
</tr>
<tr height="20" style="height:15pt">
<td height="20" style="height:15pt;padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">D</td>
<td align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">4</td>
<td class="gmail-xl63" align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">13/05/2015</td>
<td class="gmail-xl64" align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap">500,00</td>
<td align="right" style="padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11pt;font-family:Calibri,sans-serif;vertical-align:bottom;border:none;white-space:nowrap"><b>1</b></td>
</tr>
</tbody></table><br></div><div>Para esse conjunto, gostaria de gerar a coluna 'valida', que me classifica os dados da seguinte maneira: para cada local e para cada ano, retornar apenas o local de maior frequência, mais recente e de maior quantidade (nessa ordem).</div><div>Pensei em gerar um objeto para cada local a partir do which(), mas como meu conjunto de dados tem mais de 150 mil linhas e mais de 2000 locais, achei que essa abordagem não seria muito prática nem rápida de ser processada. </div><div><br></div><div>Desde já, agradeço pela colaboração de todos!</div><div><br></div><div>Att</div><div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Yury Duarte<br></div>Engenheiro Agrônomo - ESALQ/USP<br></div></div></div></div></div>