Probably it's a simple question and I dunno whats the term I have to search but I haven't find anything yet.
I have a data.table (I'm used to it) or data.frame like this:
a = rep(1, 8)
b = rep(c("20","30", "180", "10"), each = 1)
df = data.table(a,b)
df
a b
1 1 20
2 1 30
3 1 180
4 1 10
5 1 20
6 1 30
7 1 180
8 1 10
I want to obtain a variable that identify the group of observations that appear between the first and last observation with a value of b higher or equally to 180. Like this:
a b c
1 1 20 1
2 1 30 1
3 1 180 2
4 1 10 2
5 1 20 2
6 1 30 2
7 1 180 3
8 1 10 3
Any help wil be very helpful! If there's an existing question like this anywhere I will appreciate if you tell me were to look.
Thanks in advance :)