Re: [R] Calculate difference between dates in years

2010-09-17 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

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 - leap

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.birth)/365.25)