I'm sure something similar has been asked, but I'm kind of new to R and can not find something that works. I'm using the forecast package to create a moving average from a year's worth of data. I would like run this function:
CityColl$cnt_ma <- ma(CityColl$clean_cnt, order=7)
But separately for each city.
I've tried split and apply functions something like this:
CityColl$cnt_ma <- ddply(CityColl, .(city), ma(CityColl$clean_cnt, order=7))
But this seems to be very wrong...
start_time city clean_cnt
<date> <chr> <int>
1 2016-01-01 Boston 242
2 2016-01-01 Chicago 935
3 2016-01-01 Washington 3220
4 2016-01-01 Philly 639
5 2016-01-02 Boston 221
6 2016-01-02 Chicago 1421
7 2016-01-02 Washington 4922
8 2016-01-02 Philly 549
9 2016-01-03 Boston 245
10 2016-01-03 Chicago 1399