Created
July 28, 2014 12:45
-
-
Save mokjpn/24d10d16bcf37b361a63 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# plusMonth(time, diff) | |
# POSIXltに変換可能な型で与えられた日付を表すx に対して、diff月増減させた日付をPOSIXctで返す。 | |
# 月だけを増減させ、日付はそのままにするので、検査スケジュールなどを扱うのに適しているか。 | |
# diffは負でもよい。 | |
plusMonth <- function(x, diff=1) { # diff を省略すると1としたことになる | |
cur <- as.POSIXlt(x) | |
mon <- cur$mon | |
cur$year <- cur$year + (mon+diff)%/% 12 | |
cur$mon <- (mon+diff) %% 12 | |
return(as.POSIXct(cur)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment