Create end of the month date from a date variable

前端 未结 8 535
抹茶落季
抹茶落季 2020-12-03 06:27

I have a large data frame with date variables, which reflect first day of the month. Is there an easy way to create a new data frame date variable that represents the last d

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-03 07:01

    We can also use bsts::LastDayInMonth:

    transform(df, date.end.month = bsts::LastDayInMonth(df$date.start.month))
    
    #   date.start.month date.end.month
    # 1       2012-01-01     2012-01-31
    # 2       2012-02-01     2012-02-29
    # 3       2012-03-01     2012-03-31
    # 4       2012-04-01     2012-04-30
    

提交回复
热议问题