I have the following data frame:
df <- structure(list(s_do_h_patients_state = c("NC", "NC", NA, NA,
"MN", "MN", "UT", "UT", "IL", "IL"), diabetes = c(FALSE, TRUE,
FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE), n = c(24191L,
5684L, 24386L, 3820L, 18768L, 2423L, 19732L, 1313L, 15670L, 2336L
), p = c(0.809740585774059, 0.190259414225941, 0.864567822449124,
0.135432177550876, 0.88565900618187, 0.11434099381813, 0.937609883582799,
0.0623901164172012, 0.870265467066533, 0.129734532933467), N = c(29875L,
29875L, 28206L, 28206L, 21191L, 21191L, 21045L, 21045L, 18006L,
18006L)), row.names = c(NA, -10L), class = c("tbl_df", "tbl",
"data.frame"))
I would like to add another column enumerating the groups, such that the output would be c(1,1,2,2,3,3...).
One way to do it would be group_indices, but this orders alphabetically rather than by group size.
What's the correct way to achieve this?