Say that I have the following vector:
dat <- c(1,0,-1,1,0,-1,1,0,1)
I want a vector that counts the occurences of 1, 0 an -1 in dat but as an ongoing tally. The solution would look like so:
tally <- c(1,1,1,2,2,2,3,3,4)
So essentially my new vector has an ongoing tally of 1, 0 and -1 from dat. I am looking for a way to do this calculation in R so I can use it on a much larger set.