This is my data
structure(list(group = c("A", "A", "A", "B", "B", "B", "C", "C",
"C", "D", "D", "D"), type = c("T1", "T2", "T3", "T1", "T2", "T3",
"T1", "T2", "T3", "T1", "T2", "T3"), value = c("MC", "C", NA,
"C", "C", NA, "MA", "A", "A", NA, "MA", "MA")), row.names = c(NA,
-12L), class = c("tbl_df", "tbl", "data.frame"))
# A tibble: 12 x 3
group type value
<chr> <chr> <chr>
1 A T1 MC
2 A T2 C
3 A T3 NA
4 B T1 C
5 B T2 C
6 B T3 NA
7 C T1 MA
8 C T2 A
9 C T3 A
10 D T1 NA
11 D T2 MA
12 D T3 MA
For each group there are 3 types. When there is a 'M' value in the group (MC or MA) then the rest of the values in the group should be changed to that value but the NA should remain as NA.
This is my expected output:
# A tibble: 12 x 3
group type value
<chr> <chr> <chr>
1 A T1 MC
2 A T2 MC
3 A T3 NA
4 B T1 C
5 B T2 C
6 B T3 NA
7 C T1 MA
8 C T2 MA
9 C T3 MA
10 D T1 NA
11 D T2 MA
12 D T3 MA