Just expanding on Brians code to something that will work for vector.
age_years <- function(first, second)
{
lt <- data.frame(first, second)
age <- as.numeric(format(lt[,2],format="%Y")) -
as.numeric(format(lt[,1],format="%Y"))
first <
as.Date(paste(format(lt[,1],format="%Y"),"-",
On Mon, 24 Sep 2007, Alberto Monteiro wrote:
> Daniel Brewer wrote:
>>
>> I would like to be able to calculate the age of someone at a particular
>> date. Both dates are date objects. Here is what I have come up with:
>>
>> floor(as.numeric(sampleInfo$Date.of.DIAGNOSIS-
>> sampleInfo$Date.of.bir
Daniel Brewer wrote:
>
> I would like to be able to calculate the age of someone at a particular
> date. Both dates are date objects. Here is what I have come up with:
>
> floor(as.numeric(sampleInfo$Date.of.DIAGNOSIS-
> sampleInfo$Date.of.birth)/365.25)
>
> Is this the best approach?
>
No - l
L PROTECTED]
Subject: [R] Calculate difference between dates in years
Hello,
I would like to be able to calculate the age of someone at a particular
date. Both dates are date objects. Here is what I have come up with:
floor(as.numeric(sampleInfo$Date.of.DIAGNOSIS-sampleInfo$Date.of.birth)/365.2
Hello,
I would like to be able to calculate the age of someone at a particular
date. Both dates are date objects. Here is what I have come up with:
floor(as.numeric(sampleInfo$Date.of.DIAGNOSIS-sampleInfo$Date.of.birth)/365.25)
Is this the best approach? or is there an inbuilt function? I hav
5 matches
Mail list logo