我的数据框架如下:
set.seed(1)
MyDates <- ISOdatetime(2012, 1, 1, 0, 0, 0, tz = "GMT") + sample(1:27000, 500)
使用cut
df <- data.frame(table(cut(MyDates, breaks = "5 mins")))
它给我间隔
00:00:00 -- 00:05:00,
00:05:00 -- 00:10:00
但是,如果我想将“自定义”间隔作为
,那该怎么办?00:00:00 -- 00:05:00,
00:01:00 -- 00:06:00,
00:02:00 -- 00:07:00
任何帮助将不胜感激!
答案 0 :(得分:1)
你只需要传递一个数值向量来剪切。
一个例子:
data.frame(table(cut(MyDates,
c(min(MyDates), ## "Leftmost" cut
min(MyDates) + 5000, ## Custom cut 1
min(MyDates) + 17000, ## Custom cut 2
min(MyDates) + 65000),## "Rightmost" cut
right = TRUE))) ## let cut() know where should the infinite be closed or open.