我有一个对象,其中包含用户帐户的创建和结束日期:
> user
ID Create End
1 2014-01-03 2015-01-02
2 2012-03-10 2014-10-24
3 2013-09-10 2015-01-04
我需要确定每月的有效帐户数量,例如:
> active accounts
Month Count
2013-12 2
2014-01 3
2014-02 3
答案 0 :(得分:1)
使用:
$("#numberofpassengers").change(function() {
var strNumb = $('#numberofpassengers').val().toString();
var intNumb = parseInt(strNumb);
for (var i = 1; i < intNumb; i++) {
Html.Partial("_PassengerForm");
}
});
你得到:
library(data.table)
setDT(dat)[, .(mon = format(seq.Date(Create,End,'month'), '%Y-%m')), by = ID
][order(mon), .N, by = mon]
与 mon N
1: 2012-03 1
2: 2012-04 1
3: 2012-05 1
4: 2012-06 1
5: 2012-07 1
6: 2012-08 1
7: 2012-09 1
8: 2012-10 1
9: 2012-11 1
10: 2012-12 1
11: 2013-01 1
12: 2013-02 1
13: 2013-03 1
14: 2013-04 1
15: 2013-05 1
16: 2013-06 1
17: 2013-07 1
18: 2013-08 1
19: 2013-09 2
20: 2013-10 2
21: 2013-11 2
22: 2013-12 2
23: 2014-01 3
24: 2014-02 3
25: 2014-03 3
26: 2014-04 3
27: 2014-05 3
28: 2014-06 3
29: 2014-07 3
30: 2014-08 3
31: 2014-09 3
32: 2014-10 3
33: 2014-11 2
34: 2014-12 2
相当的上述内容:
dplyr