R 计算月龄
library(lubridate)
calc_age <- function(birthDate, refDate = Sys.Date()) {
require(lubridate)
period <- as.period(interval(birthDate, refDate),unit = "days")
period$day
}
#满8月龄
ymd('2020-05-31') %m-% months(3*12)
ymd('2019-12-31') %m+% months(1:12)
calc_age <- function(birthDate, refDate = Sys.Date()) {
require(lubridate)
period <- as.period(interval(birthDate, refDate),unit = "days")
period$day
}
#满8月龄
ymd('2020-05-31') %m-% months(3*12)
ymd('2019-12-31') %m+% months(1:12)
评论
发表评论