将具有每日数据的csv文件汇总到月份

时间:2018-11-12 18:55:48

标签: r csv date aggregate

我有一个名为Crime.csv的csv文件,如下所示:-

OFFENSE_CODE    OFFENSE_TYPE        OFFENSE_DESCRIPTION             DISTRICT    DAY YEAR    MONTH   STREET          NO_OF_CRIME
1106            Confidence Games    FRAUD - CREDIT CARD / ATM FRAUD     B2      1   2018    2       WASHINGTON ST   1
3201            Property Lost       PROPERTY - LOST                     B2      15  2018    3       ELM HILL AVE    1
1001            Counterfeiting      FORGERY / COUNTERFEITING            D4      9   2018    1       TREMONT ST      1
2629            Harassment          HARASSMENT                          E5      1   2018    1       CROWN POINT DR  1
1001            Counterfeiting      FORGERY / COUNTERFEITING            E5      8   2018    4       REDGATE RD      1
1106            Confidence Games    FRAUD - CREDIT CARD / ATM FRAUD     D4      22  2018    2       BOYLSTON ST     1
2629            Harassment          HARASSMENT                          B2      9   2017    10      AKRON ST        1
1102            Fraud               FRAUD - FALSE PRETENSE / SCHEME     A7      25  2018    4       LIVERPOOL ST    1
3201            Property Lost       PROPERTY - LOST                     D14     1   2018    1       FIDELIS WAY     1
1106            Confidence Games    FRAUD - CREDIT CARD / ATM FRAUD     E5      12  2018    4       SPRING ST       1
3201            Property Lost       PROPERTY - LOST                     A1      30  2018    4       NASHUA ST       1

我需要根据OFFENCE_CODE将这些数据汇总为每月数据。这样,NO_OF_CRIMES就可以汇总到该特定月份。任何帮助都将非常棒。

2 个答案:

答案 0 :(得分:0)

假设x是数据框的名称:

aggregate(x$NO_OF_CRIME, by = list(x$OFFENCE_CODE, x$MONTH), FUN = sum)

答案 1 :(得分:0)

我们可以使用<HashRouter> <Navbar /> <Route exact path="/" component={Option} /> <Route path="/finalizar3" render={props => <Checkout1 shoppingCart={this.state.shoppingCart} />} /> <Modal /> </HashRouter>

tidyverse