ageify: Calculate Age (or Time Difference) from Dates

Description Usage Arguments Value Examples

View source: R/functions.R

Description

Calculates the difference between two dates and returns a numeric value (Age).

Usage

1
ageify(DoEvent, DoBirth, format = "years")

Arguments

DoEvent

a vector of class 'Date'

DoBirth

a vector of class 'Date'

format

unit in which the output should be returned. Options are "years" (default), "months" and "days".

Value

Returns a numerical vector of the time difference between the two input vector Dates, calculated as DoEvent - DoBirth. Output can be given in units of years (default), months or days, specified in format.

Examples

1
2
3
4
5
6
7
#Calculate age of onset (from ResearchR package).
Age_onset <- ageify(d4$DoO, d4$DoB)

# For data.table output in ResearchR package
library(data.table)
d4[, c("AoO", "AoDiag") := lapply(.SD, ageify, DoBirth=DoB), 
   .SDcols=c("DoO","DoDiag")]

UMCUneuro/MRI documentation built on May 25, 2019, 1:36 p.m.