I have an R data frame:
> tab1
pat t conc
1 P1 0 788
2 P1 5 720
3 P1 10 655
4 P2 0 644
5 P2 5 589
6 P2 10 544
I am trying to create a new column for conc as a percentage of conc at t=0 for each patient. As well as many other things, I have tried:
tab1$conct0 <- tab1$conc / tab1$conc[tab1$t == 0 & tab1$pat == tab1$pat]
But I am clearly miles off with the correct code that means “conc WHERE t==0 AND pat == pat for this particular row”
I am sure I could use a for loop or something but hoped there was something easier?
Thanks
I would find the starting concentration for each patient with:
which gives (from your example data)
After that you can use
applywhich gives you