R-统计每个客户的信用交易数量

R-统计每个客户的信用交易数量,r,dataframe,counting,R,Dataframe,Counting,我有一个看起来像这样的数据集。我需要从给定的数量中计算客户进行的信用交易的数量 >head(reqDs,15) Txn_date Cust_no Acct_no cust_type Credit 1 2013-12-02 14607902 203612500 I 400.00 2 2013-12-02 14607902 203612500 I 300.00 3 2013-12-02 14607562 1603700605

我有一个看起来像这样的数据集。我需要从给定的数量中计算客户进行的信用交易的数量

>head(reqDs,15)
 Txn_date  Cust_no    Acct_no cust_type   Credit
1  2013-12-02 14607902  203612500         I   400.00
2  2013-12-02 14607902  203612500         I   300.00
3  2013-12-02 14607562 1603700605         I   304.71
4  2013-12-02 14607162 1405015800         O   475.00
5  2013-12-02 14607002  201694364         I   325.00
6  2013-12-02 14604662 1884614220         I  1390.00
7  2013-12-02 14604302  605847862         I   100.00
8  2013-12-02 14603582 1077033921         I   500.00
9  2013-12-02 14602322 1281344287         I     5.00
10 2013-12-02 14602322 1281344287         I   130.00
11 2013-12-02 14601322  204827461         O 15975.00
12 2013-12-02 14601322  204827461         O  3711.00
13 2013-12-02 14601322  204827461         O 12530.50
14 2013-12-02 14601080  465277103         O  3312.00
15 2013-12-02 14601080  465277103         O   370.00
我尝试过使用aggregate()然后应用plyr包中的count()函数

noOfTxns <- aggregate(reqDs$Credit, by=list(reqDs$Cust_no), FUN=count)
如何获得与此完全相同的所需输出

    Cust_no  No_of_txns
1   14722    1
2   15502    1
3   15942    1
4   15948    2
5   16122    3
6   16442    4

礼节:@RichardScriven

答案是使用长度而不是计数

noOfTxns <- aggregate(reqDs$Credit, by=list(reqDs$Cust_no), FUN=length)

noOfTxns我想你想要的是
length
而不是
count
好了@RichardScriven!!我知道了。在
dplyr
中,这与
count(df,Cust\u no)
noOfTxns <- aggregate(reqDs$Credit, by=list(reqDs$Cust_no), FUN=length)