I have a data frame with a grouping variable "id" and a string variable "id_c". Within each group, there may be an 'id_c' with one or more trailing >.
example_df <- data.frame(
id = c(1, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5),
id_c = c("1", "1" , "1>", "2", "2", "3", "3", "4", "4", "4", "4>>", "5", "5>"))
id id_c
1 1 1 #
2 1 1 #
3 1 1> # one trailing > in group 1
4 2 2
5 2 2
6 3 3
7 3 3
8 4 4 #
9 4 4 #
10 4 4 #
11 4 4>> # two trailing > in group 4
12 5 5 #
13 5 5> # one trailing > in group 5
For each 'id', if there is an 'id_c' value with trailing > or >>, I want to paste either > or >> to the remaining rows (i.e. originally lacking >). It is a little hard to describe in words so here is my desired output:
id id_c
1 1 1>
2 1 1>
3 1 1>
4 2 2
5 2 2
6 3 3
7 3 3
8 4 4>>
9 4 4>>
10 4 4>>
11 4 4>>
12 5 5>
13 5 5>