If we want to use cur_group_id, do a nested grouping and then extract the column
library(dplyr)
df %>%
group_by(prop) %>%
mutate(well_rep2 = cur_data() %>%
group_by(well)%>%
transmute(out = cur_group_id()) %>%
pull(out))
-output
# A tibble: 40 x 4
# Groups: prop [2]
well prop well_rep well_rep2
<chr> <int> <int> <int>
1 C03 0 1 1
2 C03 0 1 1
3 C03 0 1 1
4 C03 0 1 1
5 C03 0 1 1
6 C05 0 2 2
7 C05 0 2 2
8 C05 0 2 2
9 C05 0 2 2
10 C05 0 2 2
# … with 30 more rows
ddata
df <- structure(list(well = c("C03", "C03", "C03", "C03", "C03", "C05",
"C05", "C05", "C05", "C05", "C05", "C05", "D02", "D02", "D02",
"D02", "D02", "D02", "D02", "D02", "D02", "E07", "E07", "E07",
"E07", "E07", "E07", "E07", "E07", "E07", "E07", "E07", "F02",
"F02", "F02", "F02", "F02", "F02", "F02", "F02"), prop = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 50L, 50L, 50L, 50L,
50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L,
50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L), well_rep = c(1L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L)), class = "data.frame", row.names = c(NA,
-40L))