I am trying to calculate weight loss over period of time, therefore the initial weight is quite important. I want to create a column 'Initial weight' based on the weight at 'Day'=0 for each tray. Example is below:
Day Tray Weight Initial Weight
0 1 3303 3303
3 1 3302.4 3303
6 1 3303 3303
15 1 3295.3 3303
36 1 3281.2 3303
0 2 3428 3428
3 2 3426 3428
6 2 3425 3428
15 2 3422 3428
36 2 3417 3428
Once I have the initial Weight values then I can calculate my weight loss in a new column: (Initial Weight-Weight(t))/Initial weight.
data.frame(
Day = c(0L, 3L, 6L, 15L, 36L, 0L, 3L, 6L, 15L, 36L),
Tray = c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L),
Weight = c(3303, 3302.4, 3303, 3295.3, 3281.2, 3428, 3426, 3425, 3422, 3417)
)