I am working with a dataframe which looks similar to this
Ind Pos Sample  Ct      LogConc     RelConc
1   B1  wt1A    26.93   -2.0247878  0.009445223
2   B2  wt1A    27.14   -2.0960951  0.008015026
3   B3  wt1B    26.76   -1.9670628  0.010787907
4   B4  wt1B    26.94   -2.0281834  0.009371662
5   B5  wt1C    26.01   -1.7123939  0.019391264
6   B6  wt1C    26.08   -1.7361630  0.018358492
7   B7  wt1D    25.68   -1.6003396  0.025099232
8   B8  wt1D    25.75   -1.6241087  0.023762457
9   B9  wt1E    22.11   -0.3881154  0.409151879
10  B10 wt1E    22.21   -0.4220713  0.378380453
11  B11 dko1A   22.20   -0.4186757  0.381350463
12  B12 dko1A   22.10   -0.3847199  0.412363423
My goal is to calculate the sample wise average of the RelConc, which would result in a dataframe which would look something like this.
Ind Pos Sample  Ct      LogConc     RelConc     AverageRelConc
1   B1  wt1A    26.93   -2.0247878  0.009445223 0.008730124
2   B2  wt1A    27.14   -2.0960951  0.008015026 0.008730124
3   B3  wt1B    26.76   -1.9670628  0.010787907 0.010079785
4   B4  wt1B    26.94   -2.0281834  0.009371662 0.010079785
5   B5  wt1C    26.01   -1.7123939  0.019391264 0.018874878
6   B6  wt1C    26.08   -1.7361630  0.018358492 0.018874878
7   B7  wt1D    25.68   -1.6003396  0.025099232 0.024430845
8   B8  wt1D    25.75   -1.6241087  0.023762457 0.024430845
9   B9  wt1E    22.11   -0.3881154  0.409151879 0.393766166
10  B10 wt1E    22.21   -0.4220713  0.378380453 0.393766166
11  B11 dko1A   22.20   -0.4186757  0.381350463 0.396856943
12  B12 dko1A   22.10   -0.3847199  0.412363423 0.396856943
I am fairly new to R and have no idea how to accomplish such a seemingly simple task. In python, I'd probably loop through each row and check if I have encountered a new sample name and then calculate the average for all samples above. However this seems not very "R like". If somebody could point me to a solution, I'd be very happy!
Cheers!