I have a data frame that currently looks like this:
Month Park
<date> <chr>
2019-04-01 Arbour Lake East
2019-07-01 Arbour Lake East
2019-07-01 Arbour Lake East
2019-09-01 Arbour Lake East
2019-09-01 Arbour Lake East
2019-10-01 Arbour Lake East
2020-01-01 Arbour Lake East
2020-01-01 Arbour Lake East
2020-02-01 Arbour Lake East
2020-02-01 Arbour Lake East
2020-03-01 Arbour Lake East
2020-04-01 Arbour Lake East
2020-05-01 Arbour Lake East
2020-11-01 Arbour Lake East
2020-12-01 Arbour Lake East
2021-04-01 Arbour Lake East
2019-09-01 Arbour Lake West
2019-09-01 Arbour Lake West
2019-10-01 Arbour Lake West
2020-05-01 Arbour Lake West
I would like to create a new column, Month id, where 1 is the first month found in a specific park, and 2 is the second month in that same park (independently on whether or not these months are actually consecutive. For example, 1 could be September because it's the first month in Nosehill gravel pit Park, and 2 would be November because it's the second month in Nosehill gravel pit Park). Some id (1, 2, 3, ...) would be the same within different parks as they only represent the first month in a park. Months that are exactly the same (month/year) within the same park would also receive the same id.
Here is what I would like that column to look like:
Month Month_id Park
2019-04-01 01 Arbour Lake East
2019-07-01 02 Arbour Lake East
2019-07-01 02 Arbour Lake East
2019-09-01 03 Arbour Lake East
2019-09-01 03 Arbour Lake East
2019-10-01 04 Arbour Lake East
2020-01-01 05 Arbour Lake East
2020-01-01 05 Arbour Lake East
2020-02-01 06 Arbour Lake East
2020-02-01 06 Arbour Lake East
2020-03-01 07 Arbour Lake East
2020-04-01 08 Arbour Lake East
2020-05-01 09 Arbour Lake East
2020-11-01 10 Arbour Lake East
2020-12-01 11 Arbour Lake East
2021-04-01 12 Arbour Lake East
2019-09-01 01 Arbour Lake West
2019-09-01 01 Arbour Lake West
2019-10-01 02 Arbour Lake West
2020-05-01 03 Arbour Lake West
I really don't know how to do this, so any lead would be really appreciated!
More info:
> dput(Data.frame[1:4])
structure(list(Month = structure(c(18383, 18383, 18414, 18414,
18444, 18718, 18322, 18687, 18687, 18293, 18293, 18383, 18444,
18475, 18506, 18536, 18567, 18567, 18628, 18748, 18748, 18779,
18809, 18078, 18078, 18109, 18109, 18628, 18628, 18444, 18444,
18475), class = "Date"), Park = c("Aspen Heights", "Aspen Heights",
"Aspen Heights", "Aspen Heights", "Aspen Heights", "Aspen Heights",
"Auburn Bay", "Auburn Bay", "Auburn Bay", "Bayview", "Bayview",
"Bayview", "Bayview", "Bayview", "Bayview", "Bayview", "Bayview",
"Bayview", "Bayview", "Bayview", "Bayview", "Bayview", "Bayview",
"Cranston", "Cranston", "Cranston", "Cranston", "Cranston", "Cranston",
"Currie Barracks", "Currie Barracks", "Currie Barracks"), Aggr_Code = c("1",
"2", "1", "2", "1", "1", "1", "1", "2", "1", "2", "1", "1", "1",
"1", "1", "1", "2", "1", "1", "2", "1", "1", "1", "2", "1", "2",
"1", "2", "1", "2", "1"), AC_events_per_month = c(4, 1, 4, 1,
2, 1, 1, 2, 1, 1, 1, 1, 3, 2, 4, 2, 6, 2, 3, 1, 1, 1, 1, 8, 4,
2, 1, 3, 3, 2, 1, 1)), row.names = c(NA, -32L), groups = structure(list(
Month = structure(c(18078, 18109, 18293, 18322, 18383, 18383,
18414, 18444, 18444, 18444, 18475, 18475, 18506, 18536, 18567,
18628, 18628, 18687, 18718, 18748, 18779, 18809), class = "Date"),
Park = c("Cranston", "Cranston", "Bayview", "Auburn Bay",
"Aspen Heights", "Bayview", "Aspen Heights", "Aspen Heights",
"Bayview", "Currie Barracks", "Bayview", "Currie Barracks",
"Bayview", "Bayview", "Bayview", "Bayview", "Cranston", "Auburn Bay",
"Aspen Heights", "Bayview", "Bayview", "Bayview"), .rows = structure(list(
24:25, 26:27, 10:11, 7L, 1:2, 12L, 3:4, 5L, 13L, 30:31,
14L, 32L, 15L, 16L, 17:18, 19L, 28:29, 8:9, 6L, 20:21,
22L, 23L), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), row.names = c(NA, -22L), class = c("tbl_df",
"tbl", "data.frame"), .drop = TRUE), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"))