r - lubridate, calculate years, return NA -


hello have problem calculation age of subject knowing date of birth, using the lubridate package, sample:

> head(df$hs_dob1c) [1] 2002-01-30 2004-12-29 2005-09-15 2002-12-20 2005-07-28 1995-08-28 

firstly set:

df$hs_dob1c <- as.date(df$hs_dob1c, format='%y-%m-%d') 

then:

today <- as.date(sys.date(), format="%y-%m-%d") ref_date <- as.date(df$hs_dob1c, format="%y-%m-%d") 

the problem when set reference because:

> head(df$hs_dob1c) [1] na na na na na na 

not sure used lubridate, try

df$hs_dob1c <- as.date(df$hs_dob1c, format='%y-%m-%d') 

instead of

df$hs_dob1c <- as.date(df$hs_dob1c, format='%y-%m-%d') 

%y indicates 2-digit year, have 4-digit year should referred %y


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -