I have a question about date end, I explain in the following.
Here is my example data:
DATE
2015-01-01
2015-02-05
2015-09-29
2016-02-07
2016-07-24
2016-12-16
I know if I want the total days in that month, the code is:
days_in_month(DATE)
However, what I want is as following:
DATE DATE_Month_End
2015-01-01 2015-01-31
2015-02-05 2015-02-28
2015-09-29 2015-09-30
2016-02-07 2016-02-29
2016-07-24 2016-07-31
2016-12-16 2016-12-31
any suggestion?
You can do this with:
library(lubridate)
DATE$DATE_Month_End <- DATE$DATE
day(DATE$DATE_Month_End) <- days_in_month(DATE$DATE)
since day() <-
lets you change the day while keeping the year and month.
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