How to create a new variable βCountWKβ based on counting the values ββin βWKβ that occur before the first instance of β1β in βPerformanceβ, grouped by βIDβ?
ID<-c('A', 'A', 'A', 'B', 'B', 'B', 'C', 'C', 'C', 'C', 'C')
WK<-c(1, 2, 3, 1, 2, 3, 1, 2, 3, 4, 5)
Performance<-c(0,1,1,0,1,0,0,1,0,1,1)
Data<-data.frame(ID, WK, Performance)
So, for ID "A" CountWk will be "2", for "B" "2", and for C "2" with a N / A value in "CountWk" for every other row except the one that contains the first instance of "1 "in" Productivity. "