Skip to content

Time data

3 messages · Marc Bernard, PIKAL Petr, Gabor Grothendieck

#
Hi
On 20 Dec 2005 at 11:12, Marc Bernard wrote:
Date sent:      	Tue, 20 Dec 2005 11:12:28 +0100 (CET)
From:           	Marc Bernard <bernarduse1 at yahoo.fr>
To:             	r-help at stat.math.ethz.ch
Subject:        	[R] Time data
this is in attributes of an output and is not changed by calculations
as.numeric(as.Date(df$date_exam)-as.Date(df$date_birth))/365

However you can use it in calculations without problem as I suppose 
that "Time difference of" results from print method of a difftime 
object.
as.Date(df$date_exam)-as.Date(df$date_birth)

HTH
Petr
Petr Pikal
petr.pikal at precheza.cz
#
On 12/20/05, Marc Bernard <bernarduse1 at yahoo.fr> wrote:
First ensure that df stores its dates using "Date" class in the first
place.  If your data is stored in the correct representation then
everything becomes easier subsequently:

fmt <- "%d/%m/%Y"
df[,2] <- as.Date(df[,2], fmt)
df[,3] <- as.Date(df[,3], fmt)

# converting them to numeric gives the number of days since
# the Epoch and one can just subtact those:

(as.numeric(df$date_exam) - as..numeric(df$date_birth)) / 365

R News 4/1 Help Desk article has more info on dates.