Hi Christophe,
Thanks so much for that, that's a really elegant solution. I had looked at accumulate()
before but couldn't figure out how to apply it to this type of problem.
I realise now that my reprex is perhaps overly simplified and doesn't capture what it is that I'm trying to do...