Forcing end of quarter date for as.Date(as.yearqtr())
问题 as.yearqtr() from the zoo package appears to use the beginning of the quarter: library(zoo) x <- "2015-05-17" x <- as.Date(x) x <- as.Date(as.yearqtr(x)) x # [1] "2015-04-01" How might I instead grab the end of quarter? x # [1] "2015-06-30" Thanks! 回答1: Use frac = 1 as shown: x <- as.Date("2015-05-17") as.Date( as.yearqtr(x), frac = 1 ) giving: [1] "2015-06-30" 回答2: library(zoo) x <- as.Date("2015-05-17") x <- as.Date(as.yearqtr(x)+0.25)-1 x # [1] "2015-06-30" as.yearqtr(x)+0.25 gives you the