[英]R: cut function with breaks for every two months
I've learnt from somewhere that for Date
vector we can use cut
to split into bins: 我从某个地方学到了对于
Date
向量我们可以使用cut
来分割成bin:
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. 我试着通过
?cut
来查找它,但它甚至不会显示我可以使用'quarter'
或'month'
来打破。 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. 这是S3类的一个不幸的副作用:你需要确保你正在寻找适当的帮助。 Don't look at
?cut
, look at ?cut.Date
or ?cut.POSIXt
(as BondedDust suggests). 不要看
?cut
,看?cut.Date
或?cut.POSIXt
(如BondedDust建议的那样)。
From that help: 从那个帮助:
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".breaks
切割点或数字的向量,给出要切入的间隔数或间隔指定,“sec”,“min”,“hour”,“day”,“DSTday”,“week”之一,“月”,“季度”或“年”,可选地以整数和空格开头,或者后跟“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')
. 正如@akrun所说,对于你的情况你可以使用
cut(dates, breaks='2 months')
。
您可以使用以下内容:
cut(dates, breaks='2 month')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.