I'm beginning to get my feet wet with R, and I'm brand new to time series concepts. Can anyone point me in the right direction to calculate a monthly % change.

1. I have data for different years, with different months, in different towns & prices and the rate of change like so

.

```
i  | hrvyear |  m   | town        |   price   |  rate of change
1  |  1270   |  5   | Chesterford |   80      |  NA
2  |  1270   |  6   | Chesterford |   64      |  -20 %
3  |  1270   |  7   | Lopham      |   74      |  NA
4  |  1274   |  12  | Lopham      |   74      |  NA
5  |  1275   |  1   | Lopham      |   78      |  5,4054 % 
6  |  1275   |  2   | Lopham      |   59      |  -24,3589 %
7  |  1275   |  3   | Lopham      |   61      |  3,3898 %
8  |  1275   |  5   | Lopham      |   68      |  NA

```

2. In a second step, I want to take the average ratio of all possible pairs of the month starting in September and until August in the upper table ( -> that means, 9\_to\_10, 9\_to\_11, ..., 9\_to 8, 10\_to\_11, ..., 10\_to\_8, ... 7\_8)

.

```
i  | start_month | end_month | average_ratio | %change | Std. error | # cases
1  |  9          | 10        |  1,055        | 2,7     |   0.034    | 22
2  |  9          | 11        |   ...         | ...     |   ...      | ..
3  |  9          | 12        |   ...         | ...     |   ...      | ..
4  |  9          | 1         |   ...         | ...     |   ...      | ..
5  |  9          | 2         |   ...         | ...     |   ...      | ..
6  |  9          | 3         |   ...         | ...     |   ...      | ..
7  |  9          | 4         |   ...         | ...     |   ...      | ..
8  |  9          | 5         |   ...         | ...     |   ...      | ..
9  |  9          | 6         |   ...         | ...     |   ...      | ..
10 |  9          | 7         |   ...         | ...     |   ...      | ..
11 |  9          | 8         |   ...         | ...     |   ...      | ..
.. |  ...        | ..        |   ...         | ...     |   ...      | ..
.. |  12         | 1         |   ...         | ...     |   ...      | ..
.. |  12         | 2         |   ...         | ...     |   ...      | ..
.. |  ...        | ..        |   ...         | ...     |   ...      | ..
.. |  12         | 8         |   ...         | ...     |   ...      | ..
.. |  ...        | ..        |   ...         | ...     |   ...      | ..
66 |  7          | 8         |   ...         | ...     |   ...      | ..

```

The calculations:

Rate of change function: ((a-b)/b)\*100 , where a denotes the new month, and b the previous month

Average\_ratio: mean of the respective month during all years and towns

%change: (log(1+mean(average\_ratio))/x)\*100,
where x is the distance of start\_month and end\_month

```
structure(list(hrvyear = c(1270, 1270, 1272, 1272, 1275, 1275
), m = c(5, 12, 2, 4, 2, 3), town = c("Chesterford", "Chesterford", 
"Lopham", "Lopham", "Lopham", "Lopham"), `mean(price)` = c(80, 
64, 74, 78, 59, 61)), row.names = c(NA, -6L), groups = structure(list(
    hrvyear = c(1270, 1270, 1272, 1272, 1275, 1275), m = c(5, 
    12, 2, 4, 2, 3), .rows = structure(list(1L, 2L, 3L, 4L, 5L, 
        6L), ptype = integer(0), class = c("vctrs_list_of", "vctrs_vctr", 
    "list"))), row.names = c(NA, 6L), class = c("tbl_df", "tbl", 
"data.frame"), .drop = TRUE), class = c("grouped_df", "tbl_df", 
"tbl", "data.frame"))

```

I hope the question is clear. I appreciate any advice.