s-news
[Top] [All Lists]

Re: time date

To: jose Bartolomei <surfprjab@hotmail.com>
Subject: Re: time date
From: Sundar Dorai-Raj <sundar.dorai-raj@PDF.COM>
Date: Thu, 19 Aug 2004 15:54:49 -0500
Cc: s-news@lists.biostat.wustl.edu
In-reply-to: <BAY1-F3cnaC3y6vnJq1000953c4@hotmail.com>
Organization: PDF Solutions, Inc.
References: <BAY1-F3cnaC3y6vnJq1000953c4@hotmail.com>
Reply-to: sundar.dorai-raj@PDF.COM
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)


jose Bartolomei wrote:

Dear S-plus users,

I have two questions.

1. How can I format a numeric vector (like: 01012000) to timeDate (like: 01/01/2000)?


(Is this month/day/year or day/month/year?)

You'll have to convert the values to character and prepend a "0" to the beginning those elements that represent dates before October 1, assuming month/day/year.

x <- 12000 + 1000000 * 1:12
x <- paste(ifelse(x < 10000000, "0", ""), x, sep = "")
x.td <- timeDate(x, "%2m%2d%4Y")

2. if the time is the Birth Date. How can I calculate the age?
for example; from 01/01/2000  to  4.x year of age


today <- timeDate(date(), "%w %m %d %H:%M:%S %Z %Y")
as.numeric(today - x.td)/365.25

--sundar

BTW, all of this could be discovered by reading the help page for ?timeDate and ?class.timeDate.



<Prev in Thread] Current Thread [Next in Thread>
  • time date, jose Bartolomei
    • Re: time date, Sundar Dorai-Raj <=