I've learnt from somewhere that for Date vector we can use cut to split into bins:
cut(dates, breaks='quarter')
Now I want to change it so that it breaks by every two months, how can I do that?
I try to look it up by ?cut, but it won't even show that I can use 'quarter' or 'month' to break. Where can I find a more detailed document about this usage?
breaks:
either a numeric vector of two or more unique cut points or a single number (greater than or equal to 2) giving the number of intervals into which x is to be cut.
This is a bit of an unfortunate side-effect of S3 classes: you need to make sure you're looking at the appropriate help. Don't look at ?cut, look at ?cut.Date or ?cut.POSIXt (as BondedDust suggests).
From that help:
breaksa 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 "day", "week", "month", "quarter" and "year" are allowed.
As @akrun says, for your case you can use cut(dates, breaks='2 months').
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With