0
Assuming the following dataframe:
library(dplyr)
library(lubridate)
df<-data.frame(inicio= ymd(19800101), fim=ymd(20200101)) %>%
mutate(dif=fim-inicio)
inicio fim dif
1 1980-01-01 2020-01-01 14610 days
How do I convert those 14610 days into years (or months, or weeks)?
SEQUENCE
df %>%
mutate(em.anos= time_length(dif, unit = "year"))
inicio fim dif em.anos
1 1980-01-01 2020-01-01 40.0274 days 0.109589
I tried, but still could not: I did the sequence in the original post
– itamar
Use
interval(inicio, fim)
instead of subtraction, and then you use thetime_length
– Daniel R