I need to calculate the total amount for each user in the data set but the problem is even when the amount for the user is 0 it keeps subtracting and generating fake negative values(there can't be amount less then 0 its bug).
For every + or - there are real events. However, when the amount hits 0, no matter how many negative events appear the result should not go below 0, and if we have first 10 negative events like going to -1000 and after that we have one positive +200 and after that one negative -100, I need the final result to be 100.
Here is example, the final total amount for that user should be 200.
userdata <- read.table(text="
ID Amount UserID Date Hour
1 500 2 3/3/2018 0:00
2 -200 2 3/4/2018 0:00
3 -250 2 3/5/2018 0:00
4 -500 2 3/8/2018 0:00
5 100 2 3/8/2018 0:00
6 -50 2 3/8/2018 0:00
7 250 2 3/8/2018 0:00
8 -100 2 3/8/2018 0:00
", header=TRUE, stringsAsFactors=FALSE)
I need a way to correctly calculate that amounts.