I'm trying to determine the number of months between baseline and followup my date looks like this
-------------------------
| Baseline | Follow_Up |
-------------------------
| 10/6/15 | 10/10/17 |
| 10/6/15 | 4/20/18 |
| 10/6/15 | 4/18/18 |
| 10/6/15 | 7/2/18 |
| 10/6/15 | 8/8/17 |
| 10/6/15 | 1/17/18 |
| 10/6/15 | 10/19/17 |
--------------------------
And I looking for output as this
---------------------------------------------
| Baseline | Follow_Up | Months difference|
---------------------------------------------
| 10/6/15 | 10/10/17 |24.5 |
| 10/6/15 | 4/20/18 |30.9 |
| 10/6/15 | 4/18/18 |30.8 |
| 10/6/15 | 7/2/18 |33.3 |
| 10/6/15 | 8/8/17 |22.4 |
| 10/6/15 | 1/17/18 |27.8 |
| 10/6/15 | 10/19/17 |24.8 |
---------------------------------------------
I would like to know which package can I use to do this calculation
Thank you
Here is an option with lubridate
library(dplyr)
library(lubridate)
df1 %>%
mutate(Months_difference = (interval(mdy(Baseline),
mdy(Follow_Up))) %/% months(1))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With