Suppose I have the following data frame in R:
set.seed(5)
PosActions <- c("Work","Pause","Clockin","Clockout","Lunch")
df <- data.frame(ID = c(rep(1,3),rep(2:3,each=4),rep(4,5)),
ACTION = sample(PosActions,16,replace=T))
Which returns
ID ACTION
1 1 Pause
2 1 Clockout
3 1 Lunch
4 2 Pause
5 2 Work
6 2 Clockout
7 2 Clockin
8 3 Lunch
9 3 Lunch
10 3 Work
11 3 Pause
12 4 Clockin
13 4 Pause
14 4 Clockin
15 4 Pause
16 4 Pause
In this data frame, the rows corresponding to ID == 2 and ID == 3 (rows 4 up to 11) contain the string "Work" in the column ACTION. I am trying to find the indices of these rows. In this case:
[1] FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE
[14] FALSE FALSE FALSE
In other words, whenever a set of rows with the same ID number contains "Work" in the ACTION column, all row indices of this ID number have to be returned.
I hope someone can help me, thanks in advance.