Forcing end of quarter date for as.Date (as.yearqtr ())

as.yearqtr () from the package zoo

appears to use the start 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 can I grab the end of the block instead?

x

# [1] "2015-06-30"

      

Thank!

+3


source to share


2 answers


Use frac = 1

as shown:

x <- as.Date("2015-05-17")
as.Date( as.yearqtr(x), frac = 1 )

      



giving:

[1] "2015-06-30"

      

+5


source


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 next quarter. as.Date

gives you the first day of the next quarter. -1

returns the last day of the original quarter.

+2


source







All Articles