Skip to content

Instantly share code, notes, and snippets.

@mokjpn
Created July 28, 2014 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mokjpn/24d10d16bcf37b361a63 to your computer and use it in GitHub Desktop.
Save mokjpn/24d10d16bcf37b361a63 to your computer and use it in GitHub Desktop.
# 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