I have a dataset that is 64rX153c of data. Here are the first 4x22:
structure(list(id = c(20230420, 20230420, 2023042110, 2023042110,
2023042112, 2023042112, 2023042114, 2023042114, 2023042214, 2023042214
), condition = c("control", "control", "control", "control",
"forced_break", "forced_break", "forced_break", "forced_break",
"control", "control"), round1_win = c(1, 0, 1, 0, 0, 1, 1, 0,
0, 1), round1_sound = c(1, 1, 1, 1, 3, 3, 4, 4, 2, 2), ttrs1 = c(34.8679761886597,
34.8679761886597, 23.8744249343872, 23.8744249343872, 14.2690608501434,
14.2690608501434, 17.2876904010773, 17.2876904010773, 17.2002062797546,
17.2002062797546), ttbp1 = c(42.8691244125366, 42.8691244125366,
27.8899409770966, 27.8899409770966, 17.2830331325531, 17.2830331325531,
16.2952466011047, 16.2952466011047, 21.2042264938354, 21.2042264938354
), ttbi1 = c(50.7323212623596, 50.7323212623596, 34.1096398830414,
34.1096398830414, 38.0370643138885, 38.0370643138885, 36.0967524051666,
36.0967524051666, 29.5176334381103, 29.5176334381103), round2_win = c(0,
1, 1, 0, 0, 1, 0, 1, 1, 0), round2_sound = c(1, 1, 1, 1, 1, 1,
1, 1, 3, 3), ttrs2 = c(53.7323212623596, 53.7323212623596, 37.1107151508331,
37.1107151508331, 38.0380613803863, 38.0380613803863, 36.0967524051666,
36.0967524051666, 32.5185968875885, 32.5185968875885), ttbp2 = c(57.7340142726898,
57.7340142726898, 43.1248035430908, 43.1248035430908, 40.04527759552,
40.04527759552, 40.1092526912689, 40.1092526912689, 34.5237216949463,
34.5237216949463), ttbi2 = c(69.872288942337, 69.872288942337,
47.0448129177094, 47.0448129177094, 59.3737871646881, 59.3737871646881,
61.5298793315888, 61.5298793315888, 45.1512970924377, 45.1512970924377
), round3_win = c(1, 0, 0, 1, 1, 0, 1, 0, 0, 1), round3_sound = c(2,
2, 1, 1, 8, 8, 8, 8, 2, 2), ttrs3 = c(72.872288942337, 72.872288942337,
50.0448129177094, 50.0448129177094, 59.3737871646881, 59.3737871646881,
61.5298793315888, 61.5298793315888, 48.1512970924377, 48.1512970924377
), ttbp3 = c(79.8788452148437, 79.8788452148437, 55.0583190917969,
55.0583190917969, 65.3748495578766, 65.3748495578766, 65.538156747818,
65.538156747818, 54.1600811481476, 54.1600811481476), ttbi3 = c(92.00337266922,
92.00337266922, 59.4620923995972, 59.4620923995972, 85.2011280059815,
85.2011280059815, 85.9579682350159, 85.9579682350159, 58.6821427345276,
58.6821427345276), round4_win = c(1, 0, 0, 1, 1, 0, 1, 0, 1,
0), round4_sound = c(1, 1, 2, 2, 1, 1, 1, 1, 4, 4), ttrs4 = c(95.00337266922,
95.00337266922, 62.4620923995972, 62.4620923995972, 85.2011280059815,
85.2011280059815, 85.9579682350159, 85.9579682350159, 61.6821427345276,
61.6821427345276), ttbp4 = c(101.018859148026, 101.018859148026,
66.4772782325744, 66.4772782325744, 89.2028863430023, 89.2028863430023,
91.9701442718506, 91.9701442718506, 65.6861252784729, 65.6861252784729
), ttbi4 = c(105.467720985413, 105.467720985413, 70.9975862503052,
70.9975862503052, 109.391041994095, 109.391041994095, 111.622535705566,
111.622535705566, 71.7297728061676, 71.7297728061676)), row.names = c(NA,
-10L), class = c("tbl_df", "tbl", "data.frame"))
This represents data from a game with multiple rounds. I want to plot the mean round_sound of player1 by player2. Every row is one of two people that competed against each other, where the same id means the two were part of the same pair. Round_win is binary, 1 for the participant, 0 for the opponent (hence why the round_win is the reverse from p1 and p2 in a pair).
So, I need to be able to take the mean of all round_sound occurrences where round_win == 1 and add it as a new column in the df. I then need to take the mean of all round_sound occurrences where round_win == 0 and add that to another new column. I have a string of the column number for all the relevant round_sound columns, and another for all the round_win columns. I suspect that will help but I don't know how to put it to use.
Edit for Clarity:
I think I should be able to do the above with something like rowMeans(dataset[c(3, 8, 13, 18)] **where** dataset[c(4, 9, 14, 19)] == 1)
. I expect this to mean "find the mean of [the first set of columns] when [the second set of columns] == 1). I do not know how to code in the "where" part. I'm not sure that helps but I hope it does.
tyia