Re: [R] Calculate difference between dates in years

2010-09-16 Thread nzcoops
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"),"-",

Re: [R] Calculate difference between dates in years

2007-09-24 Thread Prof Brian Ripley
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

Re: [R] Calculate difference between dates in years

2007-09-24 Thread Alberto Monteiro
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

Re: [R] Calculate difference between dates in years

2007-09-24 Thread Wayne.W.Jones
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

[R] Calculate difference between dates in years

2007-09-24 Thread Daniel Brewer
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