<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'><p abp="136"><font face="Times New Roman">
</font></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US" style="mso-ansi-language: EN-US;">Hello everyone. </span><span lang="EN-US" style="mso-ansi-language: EN-US;">I’ve the following data table:<o:p></o:p></span></p><p abp="136"><font face="Times New Roman">
</font></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US" style="mso-ansi-language: EN-US;"><o:p> </o:p></span></p><p abp="136"><font face="Times New Roman">
</font><span lang="EN-US" style="mso-ansi-language: EN-US;"><font face="Courier New"><font size="2">DT <- data.table(id=1:5,<o:p></o:p></font></font></span></p><p abp="136"><font face="Courier New"><font size="2">
<span lang="EN-US" style="mso-ansi-language: EN-US;"><span style="mso-tab-count: 1;"> </span>born=as.Date(c("1939-10-28","1943-02-26","1946-03-09","1947-05-19","1932-04-03")),<o:p></o:p></span></font></font></p><p abp="136"><font face="Courier New"><font size="2">
<span lang="EN-US" style="mso-ansi-language: EN-US;"><span style="mso-tab-count: 1;"> </span>start=as.Date(c("2012-01-01","1980-07-15","1998-10-28","2011-10-28","2010-10-28")),<o:p></o:p></span></font></font></p><p abp="136"><font face="Courier New"><font size="2">
<span lang="EN-US" style="mso-ansi-language: EN-US;"><span style="mso-tab-count: 1;"> </span>end=as.Date(c("2012-05-01","2014-02-01","2012-10-20","2013-10-15","2012-08-25")))<o:p></o:p></span></font></font></p><p abp="136"><font face="Times New Roman">
</font></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US" style="mso-ansi-language: EN-US;"><o:p><font face="Courier New">>DT</font></o:p></span></p><p abp="136"><font face="Times New Roman">
</font></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US" style='font-family: "Courier New"; mso-ansi-language: EN-US;'><span style="mso-spacerun: yes;"> </span>id<span style="mso-spacerun: yes;">
</span>born<span style="mso-spacerun: yes;"> </span>start<span style="mso-spacerun: yes;"> </span>end<o:p></o:p></span></p><p abp="136"><font face="Times New Roman">
</font><span lang="EN-US" style='font-family: "Courier New"; mso-ansi-language: EN-US;'>1:<span style="mso-spacerun: yes;"> </span>1 1939-10-28 2012-01-01 2012-05-01<o:p></o:p></span></p><p abp="136"><font face="Times New Roman">
</font><span lang="EN-US" style='font-family: "Courier New"; mso-ansi-language: EN-US;'>2:<span style="mso-spacerun: yes;"> </span>2 1943-02-26 1980-07-15 2014-02-01<o:p></o:p></span></p><p abp="136"><font face="Times New Roman">
</font><span lang="EN-US" style='font-family: "Courier New"; mso-ansi-language: EN-US;'>3:<span style="mso-spacerun: yes;"> </span>3 1946-03-09 1998-10-28 2012-10-20<o:p></o:p></span></p><p abp="136"><font face="Times New Roman">
</font><span lang="EN-US" style='font-family: "Courier New"; mso-ansi-language: EN-US;'>4:<span style="mso-spacerun: yes;"> </span>4 1947-05-19 2011-10-28 2013-10-15<o:p></o:p></span></p><p abp="136"><font face="Times New Roman">
</font><span lang="EN-US" style='font-family: "Courier New"; mso-ansi-language: EN-US;'>5:<span style="mso-spacerun: yes;"> </span>5 1932-04-03 2010-10-28 2012-08-25<o:p></o:p></span></p><p abp="136"><font face="Times New Roman">
</font></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US" style='mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New";'>I
would like to be able to keep only those subjects whose “start” date <span style="mso-spacerun: yes;"> </span>is previous to “2010-01-01” date, and then
calculate</span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US" style='mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New";'>the age they were at 2010-01-01 in a newDT:<o:p></o:p></span></p><p abp="136"><font face="Times New Roman">
</font></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US" style='mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New";'><o:p> </o:p></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US" style='font-family: "Courier New"; mso-ansi-language: EN-US;'><span style="mso-spacerun: yes;"> </span>id<span style="mso-spacerun: yes;">
</span>born<span style="mso-spacerun: yes;"> </span>start<span style="mso-spacerun: yes;"> </span>end<span style="mso-tab-count: 1;"> </span>
age<o:p></o:p></span></p><p abp="136"><font face="Times New Roman">
</font><span lang="EN-US" style='font-family: "Courier New"; mso-ansi-language: EN-US;'>2:<span style="mso-spacerun: yes;"> </span>2 1943-02-26 1980-07-15 2014-02-01<span style="mso-tab-count: 1;"> </span>66.8<o:p></o:p></span></p><p abp="136"><font face="Times New Roman">
</font><span lang="EN-US" style='font-family: "Courier New"; mso-ansi-language: EN-US;'>3:<span style="mso-spacerun: yes;"> </span>3 1946-03-09 1998-10-28 2012-10-20<span style="mso-tab-count: 1;"> </span>63.8<o:p></o:p></span></p><p abp="136"><font face="Times New Roman">
</font></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US" style='font-family: "Courier New"; mso-ansi-language: EN-US;'><o:p> </o:p></span></p><p abp="136"><font face="Times New Roman">
</font><span lang="EN-US" style='font-family: "Arial","sans-serif"; mso-ansi-language: EN-US;'><font face="Calibri">I
have:<o:p></o:p></font></span></p><p abp="136"><font face="Times New Roman">
</font><span lang="EN-US" style='font-family: "Courier New"; mso-ansi-language: EN-US;'><o:p> </o:p></span></p><p abp="136"><font face="Times New Roman">
</font><span lang="EN-US" style="mso-ansi-language: EN-US;">newDT <- DT[, if(start <= as.Date("2010-01-01"))
{<o:p></o:p></span></p><p abp="136"><font face="Times New Roman">
</font><span lang="EN-US" style="mso-ansi-language: EN-US;">list(c(id, born,
start, end, age=unclass(round(difftime(Apertura, born)/365.25,1))))<o:p></o:p></span></p><p abp="136"><font face="Times New Roman">
</font><span lang="EN-US" style="mso-ansi-language: EN-US;">} , </span></p><p abp="136"><span lang="EN-US" style="mso-ansi-language: EN-US;">by=c('id','born','start','end')]<o:p></o:p></span></p><p abp="136"><font face="Times New Roman">
</font></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US" style="mso-ansi-language: EN-US;"><o:p></o:p></span> </p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US" style="mso-ansi-language: EN-US;">But it appears an error message! </span><span lang="EN-US" style="mso-ansi-language: EN-US;">Can anyone please help me with this? Thank you!</span></p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US" style="mso-ansi-language: EN-US;"></span> </p><p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US" style="mso-ansi-language: EN-US;"><o:p></o:p></span> </p><p abp="136"><font face="Times New Roman">
</font></p> </div></body>
</html>