I would like assign group number for based on those below a threshold number. I have created a small toy example to help illustrate what I need to do in my very large data set. My dataset does have na values, which should always be the first number in the group. I suspect this is what is causing the problem.
TB <- c(na,21706,297,1078,61,75,6464,10649,3480,7823,3233,83,3646,60)
thresh = 316
This is how I would like it formatted, so those under the threshold criteria get grouped with the one above. I have included the Time series data in the picture for further illustration, but it's not necessary for the code
I have tried:
test.group <- dat %>%
mutate(grp = cumsum(TB < 316))
but only get NA values returned. Any help is appreciated.