Problems adding a month to X using POSIXlt in R - need to reset value using as.Date(X)

前端 未结 3 804
不知归路
不知归路 2020-12-22 05:14

This works for me in R:

# Setting up the first inner while-loop controller, the start of the next water year
  NextH2OYear <- as.POSIXlt(firstDate)
  Next         


        
3条回答
  •  孤城傲影
    2020-12-22 05:45

    Here is you can add 1 month to a date in R, using package lubridate:

    library(lubridate)
    x <- as.POSIXlt("2010-01-31 01:00:00")
    month(x) <- month(x) + 1
    
    >x
    [1] "2010-03-03 01:00:00 PST"
    

    (note that it processed the addition correctly, as 31st of Feb doesn't exist).

提交回复
热议问题