Converting yearmon column to last date of the month in R

前端 未结 3 1481
天命终不由人
天命终不由人 2021-01-15 03:03

I have a data frame (df) like the following:

Date        Arrivals

2014-07      100
2014-08      150
2014-09      200

I know that I can con

3条回答
  •  迷失自我
    2021-01-15 03:35

    Here is a way to do it using the zoo package.

    R code:

    library(zoo)
    df
    #      Date Arrivals
    # 1 2014-07      100
    # 2 2014-08      150
    # 3 2014-09      200
    
    df$Date <- as.Date(as.yearmon(df$Date), frac = 1)
    
    # output
    #         Date Arrivals
    # 1 2014-07-31      100
    # 2 2014-08-31      150
    # 3 2014-09-30      200
    

提交回复
热议问题