Hi! Thank you for your solution. I am currently fitting you code to my data and it looks great. Unfortunately, I have a criteria which I'm not sure how to adapt your code to and was wondering if there might be a simple fix or if I should ask the community. So the criteria I had was performing the cumulative number of days on medication for patients that took medications for >=15 consecutive days . So in the case of patient A004, they took medication for 8 days, then 3 days, then 1 day (11 days total). Since they didn't take medication for >=15 consecutive days, I won't calculate how many days they took medication for. Sorry if this is confusing. Please let me know if you would like an example. Thanks.
... View more