Mike
0
Q:

how to transform a difference in time from days to years in R

The lubridate package contains a built-in function, time_length, which can help perform this task.

time_length(difftime(as.Date("2003-04-05"), as.Date("2001-01-01")), "years")
[1] 2.257534

time_length(difftime(as.Date("2017-03-01"), as.Date("2012-03-01")),"years")
[1] 5.00274
0
start = as.Date("2012-03-01")
end = as.Date("2017-03-01")

# method 2
as.numeric(difftime(end, start, unit = "weeks")) / 52.25
0

New to Communities?

Join the community