I want to randomly delete rows of my `data`

based on given variables.

For example, if I give you the numerical variable `group`

, then randomly delete all rows of `group`

*except* the min value of `group`

(i.e., `1`

) in any random `study`

.

For example, if I give you the character variable `outcome`

, then randomly delete all rows with
any one value of `outcome`

(either `"A"`

or `"B"`

) in any random `study`

.

If I give you both `group`

and `outcome`

, then both deletions **should NOT** happen to the same `study`

because it may lead to the complete removal of that `study`

from the `data`

.

Is this possible in R? (below is a **possible desired output**)

```
m="
study group outcome
1 1 A
1 1 B
1 2 A
1 2 B
2 1 A
2 1 B
2 2 A
2 2 B
3 1 A
3 1 B
3 2 A
3 2 B
4 1 A
4 1 B
4 2 A
4 2 B
5 1 A
5 1 B
5 2 A
5 2 B
"
data <- read.table(text = m, h = T)
#===--- A POSSIBLE DESIRED OUTPUT:
# study group outcome
# 1 1 A # THIS `study` has lost `outcome B`
# 1 2 A #
# 2 1 A @ THIS `study` has lost `group 2`.
# 2 1 B @
# 3 1 B #
# 3 2 B # THIS `study` has lost `outcome A`
# 4 1 A
# 4 1 B
# 4 2 A
# 4 2 B
# 5 1 A @ THIS `study` has lost `group 2`.
# 5 1 B @
```