【发布时间】:2017-01-19 13:39:13
【问题描述】:
我有一个庞大的数据框,其中包含数百万个电子邮件地址及其开放时间。以下是我的数据框的子集。
dput(droplevels(data))
structure(list(email_address_hash = structure(1:3, .Label = c("0004eca7b8bed22aaf4b320ad602505fe9fa9d26",
"00198ee5364d73796e0e352f1d2576f8e8fa99db", "35c0ef2c2a804b44564fd4278a01ed25afd887f8"
), class = "factor"), open_times = c(" 04:39:24 10:39:43", " 21:12:04 07:05:23 06:31:24",
" 09:57:20 19:00:09")), row.names = c(NA, -3L), .Names = c("email_address_hash",
"open_times"), .internal.selfref = <pointer: 0x0000000007b60788>, class = c("data.table",
"data.frame"))
我的数据框的结构是
str(data)
Classes ‘data.table’ and 'data.frame': 3 obs. of 2 variables:
$ email_address_hash: Factor w/ 36231 levels "00012aec4ca3fa6f2f96cf97fc2a3440eacad30e",..: 2 16 7632
$ open_times : chr " 04:39:24 10:39:43" " 21:12:04 07:05:23 06:31:24" " 09:57:20 19:00:09"
- attr(*, ".internal.selfref")=<externalptr>
我要实现这两个目标
目标:-
1) 从 00:00:00 开始,每隔一小时计算我获得的每个客户的条目数。假设我们的第一个案例 open_times 的第一行是 04:39:24 和 10:39:43 。所以它得到一个计数 b/w 4:00:00- 5:00:00 和一个计数 b/w 10:00:00 和 11:00:00 以及所有其他间隔的计数为零,如 b/w 00: 00:00 和 01:00:00 等等。我只想要前两个具有最大条目数的计数。在这种情况下,它是 4:00:00-5:00:00 和 10:00:00-11:00:00 以及它们各自在其他列中的计数
2) 是否可以将时间间隔从 1 小时更改为 1.5 小时或 2 小时?
为了提供更多解释,下面是我想要的输出的图像 请建议我一些有效的方法来解决这个问题,因为我有一个大数据。如果您有不清楚的地方,请告诉我,而不是对我的问题投反对票。
【问题讨论】:
-
@akrun 你能帮帮我吗
标签: r time data.table time-series