Format date as Year/Quarter

前端 未结 8 1396
隐瞒了意图╮
隐瞒了意图╮ 2020-12-03 14:06

I have the following dataframe:

Data <- data.frame(
  date = c(\"2001-01-01\", \"2001-02-01\", \"2001-03-01\", \"2001-04-01\", \"2001-05-01\", \"2001-06-0         


        
8条回答
  •  心在旅途
    2020-12-03 14:21

    yq=function(x,prefix="%Y",combine="Q") paste0(ifelse(is.null(prefix),"",format(x,"%Y")),floor(as.numeric(format(x,"%m"))/3-1e-3)+1,sep=combine)
    

    this gives the flexibility of returning any format back that has the quarter in it

    no need for chron or zoo

    as for your example

    yq(as.Date("2013-04-30"),prefix="%y",combine="/0")
    > [1] "13/02"
    

提交回复
热议问题