Using R cut function on dates

后端 未结 2 1856
天涯浪人
天涯浪人 2020-12-31 03:49

I have a dataframe giving attendances at sports events

Crowd    matchDate
2345      1993-01-26
4567      1993-08-01
8888      1994-03-02
1298      1994-11-07         


        
2条回答
  •  情深已故
    2020-12-31 04:03

    An example of my comment.

    x <- as.Date(1:1000, origin = "2000-01-01")
    x <- cut(x, breaks = "quarter") 
    

    And then relabel as you please, if necessary.

    labs <- paste(substr(levels(x),1,4), "/", 1:4, sep="")
    x <- factor(x, labels = labs)
    

    ?cut.POSIXct
    

    breaks
    a vector of cut points or number giving the number of intervals which x is to be cut into or an interval specification, one of "sec", "min", "hour", "day", "DSTday", "week", "month", "quarter" or "year", optionally preceded by an integer and a space, or followed by "s". (For "Date" objects only interval specifications using "day", "week", "month", "quarter" and "year" are allowed.)

提交回复
热议问题