I would like a line of code that is capable of finding the median of every 3 column values in the Fin1 column. E.g First value would be 5.08 out of 1.54, 5.08 and 5.26. The second would be 5.27 out of 2.79, 5.27 and 8.12. The whole data set contains 36 rows so this operation would have to occur 12 times.
(See data frame below)
Block trial Trial Category Fin1 Fin2 Fin3 Fin4 Correct FastFin
2 1 2 1 1 1.5424 0.00000 0.00000 0.0000 1 1.5424
7 1 7 3 1 5.2617 0.97171 2.41070 3.8407 1 5.2617
9 1 9 2 1 5.0827 0.00000 0.00000 1.1977 1 5.0827
16 2 16 1 1 5.2732 1.28220 0.00000 3.0692 1 5.2732
19 2 19 2 1 8.1251 6.98210 1.52210 0.0000 1 8.1251
24 2 24 3 1 2.7960 1.87000 0.52903 0.0000 1 2.7960
The trick here is figuring out how to "group" every three consecutive rows. Once we have that, this then becomes a simple aggregate by group.
I'll use a
grpvariable to do that, calculating withcumsum((rownum - 1) %% 3 == 0)dplyr
If you needed all
Fin#columns, thenbase R
Data