Function/Date

  • Age
calc_age <- function(birthDate, refDate = Sys.Date()) {

  require(lubridate)

  period <- as.period(new_interval(birthDate, refDate),
                      unit = "year")

  period$year

}
ID_ICD9_Date1st_count_v2018_1M_random$age_ICD91st <- calc_age(ID_ICD9_Date1st_count_v2018_1M_random$date_ID_BIRTHDAY,ID_ICD9_Date1st_count_v2018_1M_random$date_ICD9_1st_date)
  • without function
Data_ori$years_20111231OD1 <- (as.Date(as.character('2011-12-31'), format="%Y-%m-%d") - as.Date(as.character(Data_ori$DateOD1st), format="%Y-%m-%d"))/365

Reference:

results matching ""

    No results matching ""