I have a vector
x <- c(1,3,5,4,3,6,2,6,8,9,0,3,5,2)
I would like to create a separate column where it only counts the 3's and would output a vector like
0,1,1,1,2,2,2,2,2,2,2,3,3,3 #set to vector y
Where it only counts when a "3" occurs in the vector and goes along with a running total. I thought initially an ifelse would work, but I also need to be within a forloop to divide y by another similar running total like total occurance of 1’s.