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))
What 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 to 11) contain the row "Work" in the ACTION column. I am trying to find the indices of these strings. 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 rowset with the same identifier number contains “Job” in the ACTION column, all index rows of that identifier number should be returned.
I hope someone can help me, thanks in advance.
source
share