[R] Time data

From: Marc Bernard <bernarduse1_at_yahoo.fr>
Date: Tue 20 Dec 2005 - 21:12:28 EST

Dear All, I wonder how to compute the age from the date of birth and the date of examination. Suppose that have the following data:    

  df <- as.data.frame(rbind(c(1,"10/08/1950","15/03/1998"), c(1,"10/08/1950","20/07/1998"), c(1,"10/08/1950","23/10/1998")))    

  names(df) <- c("ID", "date_birth", "date_exam")    

  date_birth: is the date of birth
  date_exam: date of examination    

  I used the following program to compute the value of the age :    

  difftime(strptime(as.character(df$date_exam), '%d/%m/%Y'), strptime(as.character(df$date_birth), '%d/%m/%Y'))/365.25    

  which gives me as an output:   

> Time differences of 47.59491, 47.94251, 48.20260 days

  theses values are actually the 3 ages (but

  My questions are:    

  1- Why in the output it says "days" instead of "years")    

  2- How can I obtain the output as a numeric vector, without the statement "Time difference of ....". This is in order to use it in my calculations.    

  3- Is there a way quicker and less redondant to compute the age form the date_birth and date_exam?    

  Thanks a lot,    


        [[alternative HTML version deleted]]

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Dec 20 21:22:33 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:41:40 EST