<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif">Bom dia,<br><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">Outra sugestão com {lubridate}.<br></div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default"><span style="font-family:monospace,monospace">### <code r><br></span></div><div class="gmail_default"><span style="font-family:monospace,monospace">require(lubridate)<br><br>DADOS = data.frame(<br>  NASCIMENTO = c("26/11/97", "20/03/99", "14/05/99","06/05/98", "03/01/00", "19/05/97", "01/02/01", "28/11/97", "10/02/00"),<br>  DATA_FATO = c("23/02/15", "28/03/15", "08/04/15", "08/04/15", "08/04/15", "08/05/15", "17/05/15", "03/06/15", "03/06/15"))<br><br>## converter para Date<br>DADOS$NASCIMENTO = dmy(DADOS$NASCIMENTO)<br>DADOS$DATA_FATO =  dmy(DADOS$DATA_FATO)<br><br>## calcula o intervalo em anos<br>DADOS$IDADE = as.period(interval(DADOS$NASCIMENTO, DADOS$DATA_FATO))<br><br>head(DADOS)<br># NASCIMENTO  DATA_FATO                IDADE<br># 1 1997-11-26 2015-02-23  17y 2m 28d 0H 0M 0S<br># 2 1999-03-20 2015-03-28   16y 0m 8d 0H 0M 0S<br># 3 1999-05-14 2015-04-08 15y 10m 25d 0H 0M 0S<br># 4 1998-05-06 2015-04-08  16y 11m 2d 0H 0M 0S<br># 5 2000-01-03 2015-04-08   15y 3m 5d 0H 0M 0S<br># 6 1997-05-19 2015-05-08 17y 11m 19d 0H 0M 0S<br><br>DADOS$IDADE@year  # [1] 17 16 15 16 15 17 14 17 15<br>DADOS$IDADE@month # [1]  2  0 10 11  3 11  3  6  3<br><br>### aproximações com certa imprecisão!<br><br>year(DADOS$DATA_FATO)-year(DADOS$NASCIMENTO)<br># [1] 18 16 16 17 15 18 14 18 15<br><br>floor((DADOS$DATA_FATO-DADOS$NASCIMENTO)/365.25)<br># Time differences in days<br># [1] 17 16 15 16 15 17 14 17 15<br><br></span></div><div class="gmail_default" style="font-family:verdana,sans-serif"><span style="font-family:monospace,monospace">### </code></span><br></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><span><br>================================================<br>Éder Comunello<br>Researcher at Brazilian Agricultural Research Corporation (Embrapa)<br>DSc in Agricultural Systems Engineering (USP/Esalq)<br>MSc in Environ. Sciences (UEM), <span>Agronomist (UEM)</span><br>---<br>Embrapa Agropecuária Oeste, Dourados, MS, Brazil |<O>|<br>================================================<br>GEO, -22.2752, -54.8182, 408m<br>UTC-04:00 / DST: UTC-03:00</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></div></div></div></div>
<br><div class="gmail_quote">Em 16 de junho de 2016 22:23, salah via R-br <span dir="ltr"><<a href="mailto:r-br@listas.c3sl.ufpr.br" target="_blank">r-br@listas.c3sl.ufpr.br</a>></span> escreveu:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div bgcolor="#FFFFFF" text="#000000">
    <font face="Arial">segue sugestão<br>
      <br>
      library(eeptools)<br>
      <br>
      DADOS = data.frame(<br>
              NASCIMENTO = c("26/11/97", "20/03/99",
      "14/05/99","06/05/98", "03/01/00", "19/05/97", "01/02/01",
      "28/11/97", "10/02/00"), <br>
              DATA_FATO = c("23/02/15", "28/03/15", "08/04/15",
      "08/04/15", "08/04/15", "08/05/15", "17/05/15", "03/06/15",
      "03/06/15"))<br>
      <br>
      ## converter para Date<br>
      DADOS$NASCIMENTO = as.Date(DADOS$NASCIMENTO, "%d/%m/%y")<br>
      DADOS$DATA_FATO = as.Date(DADOS$DATA_FATO, "%d/%m/%y")<br>
      <br>
      ## calcula o intervalo em anos<br>
      DADOS$IDADE = floor(age_calc(DADOS$NASCIMENTO, DADOS$DATA_FATO,
      units = "years"))<br>
      <br>
      DADOS<br>
      <br>
      saudações</font><div><div class="h5"><br>
    <br>
    <div>Em 16/06/2016 14:45, Amikobh via R-br
      escreveu:<br>
    </div>
    </div></div><blockquote type="cite"><div><div class="h5">
      
      <p><font size="+1">Prezados,</font></p>
      <p><font size="+1">Desde já, obrigado pela ajuda.</font></p>
      <p><font size="+1">Tendo duas variáveis com datas referentes a
          determinada pessoa:</font></p>
      <p>
        
      </p>
      <p>
        
        
        
        </p><table border="0" cellspacing="0">
          <colgroup width="151"></colgroup> <colgroup width="161"></colgroup>
          <tbody>
            <tr>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center" height="17">NASCIMENTO<br>
              </td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">DATA_FATO<br>
              </td>
            </tr>
            <tr>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center" height="17">26/11/97</td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">23/02/15</td>
            </tr>
            <tr>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center" height="17">20/03/99</td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">28/03/15</td>
            </tr>
            <tr>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center" height="17">14/05/99</td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">08/04/15</td>
            </tr>
            <tr>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center" height="17">06/05/98</td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">08/04/15</td>
            </tr>
            <tr>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center" height="17">03/01/00</td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">08/04/15</td>
            </tr>
            <tr>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center" height="17">19/05/97</td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">08/05/15</td>
            </tr>
            <tr>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center" height="17">01/02/01</td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">17/05/15</td>
            </tr>
            <tr>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center" height="17">28/11/97</td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">03/06/15</td>
            </tr>
            <tr>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center" height="17">10/02/00</td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">03/06/15</td>
            </tr>
          </tbody>
        </table>
      <p></p>
      <p><font size="+1">Como procedo para criar mais uma coluna que
          calcula a idade no dia da ocorrência de determinado fato? De
          tal forma que obtenha:</font></p>
      <p>
        
      </p>
      <p>
        
        
        
        </p><table border="0" cellspacing="0">
          <colgroup width="151"></colgroup> <colgroup width="161"></colgroup>
          <colgroup width="85"></colgroup> <tbody>
            <tr>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center" height="17">NASCIMENTO</td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">DATA_FATO</td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">IDADE</td>
            </tr>
            <tr>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center" height="17">26/11/97</td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">23/02/15</td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">17</td>
            </tr>
            <tr>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center" height="17">20/03/99</td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">28/03/15</td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">16</td>
            </tr>
            <tr>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center" height="17">14/05/99</td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">08/04/15</td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">15</td>
            </tr>
            <tr>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center" height="17">06/05/98</td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">08/04/15</td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">16</td>
            </tr>
            <tr>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center" height="17">03/01/00</td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">08/04/15</td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">15</td>
            </tr>
            <tr>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center" height="17">19/05/97</td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">08/05/15</td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">17</td>
            </tr>
            <tr>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center" height="17">01/02/01</td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">17/05/15</td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">14</td>
            </tr>
            <tr>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center" height="17">28/11/97</td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">03/06/15</td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">17</td>
            </tr>
            <tr>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center" height="17">10/02/00</td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">03/06/15</td>
              <td style="border-top:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #000000;border-right:1px solid #000000" align="center">15</td>
            </tr>
          </tbody>
        </table>
      <p></p>
      <p><br>
      </p>
      <p><font size="+1">Valeu, gente!</font><br>
      </p>
      <p><br>
      </p>
      <p><br>
      </p>
      <p><br>
      </p>
      <p><br>
      </p>
      <p><br>
      </p>
      <br>
      <fieldset></fieldset>
      <br>
      </div></div><pre>_______________________________________________
R-br mailing list
<a href="mailto:R-br@listas.c3sl.ufpr.br" target="_blank">R-br@listas.c3sl.ufpr.br</a>
<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>
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.</pre>
    </blockquote>
    <br>
  </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>