Skip to content
Prev 83025 / 398503 Next

Time data

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.