I don't think I clearly understand what you are trying to do but this could work as a starting point (and a proper reprex)
library(tidyverse)
my_data = data.frame(
stringsAsFactors = FALSE,
Game = c(1,1,2,2,3,3,4,4,5,5,6,
6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,
14,15,15,16,16,17,17,18,18,19,19,20,20),
id = c(3,4,3,4,3,4,3,4,3,4,3,
4,3,4,3,4,3,4,3,4,3,4,3,4,3,4,3,4,3,4,
3,4,3,4,3,4,3,4,3,4),
coin = c("2","1","2","1","1","2",
"1","1","1","2","1","2","1","1","2","1","2","2",
"2","1","2","1","2","1","1","2","1","1","1",
"2","1","2","1","1","2","1","2","2","2","1"),
winner = c("win","win","lose","lose",
"tie","tie","lose","lose","win","win","win","win",
"lose","lose","tie","tie","lose","lose","win",
"win","win","win","lose","lose","tie","tie","lose",
"lose","win","win","win","win","lose","lose","tie",
"tie","lose","lose","win","win")
)
my_data_comb <- my_data %>%
group_by(Game) %>%
mutate(coin_comb = paste(coin, collapse = ",")) %>%
ungroup()
# Part 1
my_data_comb %>%
count(Game, coin_comb, name = "count")
#> # A tibble: 20 × 3
#> Game coin_comb count
#> <dbl> <chr> <int>
#> 1 1 2,1 2
#> 2 2 2,1 2
#> 3 3 1,2 2
#> 4 4 1,1 2
#> 5 5 1,2 2
#> 6 6 1,2 2
#> 7 7 1,1 2
#> 8 8 2,1 2
#> 9 9 2,2 2
#> 10 10 2,1 2
#> 11 11 2,1 2
#> 12 12 2,1 2
#> 13 13 1,2 2
#> 14 14 1,1 2
#> 15 15 1,2 2
#> 16 16 1,2 2
#> 17 17 1,1 2
#> 18 18 2,1 2
#> 19 19 2,2 2
#> 20 20 2,1 2
# Part 2
my_data_comb %>%
count(coin_comb, winner, name = "percent") %>%
complete(coin_comb,nesting(winner), fill = list(percent = 0)) %>%
group_by(coin_comb) %>%
mutate(percent = scales::percent(percent/sum(percent)))
#> # A tibble: 12 × 3
#> # Groups: coin_comb [4]
#> coin_comb winner percent
#> <chr> <chr> <chr>
#> 1 1,1 lose 100%
#> 2 1,1 tie 0%
#> 3 1,1 win 0%
#> 4 1,2 lose 0%
#> 5 1,2 tie 33%
#> 6 1,2 win 67%
#> 7 2,1 lose 25%
#> 8 2,1 tie 25%
#> 9 2,1 win 50%
#> 10 2,2 lose 100%
#> 11 2,2 tie 0%
#> 12 2,2 win 0%
Created on 2022-03-06 by the reprex package (v2.0.1)
Note I don't think this is homework because of the previous related topics by the same user