I'm using R to analyze data. I have an ordered grouped time series that shows the brightness of a sample at different times, starting at 0
| Group | Time | Brightness | Retention |
|---|---|---|---|
| A | 0 | 100 | NA |
| A | 50 | 70 | = 70 /100 |
| A | 100 | 20 | = 20/100 |
| B | 0 | 90 | NA |
| B | 50 | 80 | = 80 /90 |
| B | 100 | 50 | = 50/90 |
To calculate retention, I have to divide by the brightness at time 0 for that group. But there are multiple time zeros throughout the table. I tried using a for loop, but due to the length of the data, this takes about 15 seconds to run; I'm looking for more efficient ways.
Thanks for helping :)