Hers is a DF for test:
test_df <- structure(list(plant_id = c("plant_1", "plant_1", "plant_1", "plant_1", "plant_1",
"plant_2", "plant_2", "plant_2", "plant_2", "plant_2",
"plant_3", "plant_3", "plant_3", "plant_3", "plant_3",
"plant_4", "plant_4", "plant_4", "plant_4", "plant_4"),
skipped = c(1, 1, 0, 1, 2,
0, 1, 1, 0, 2,
1, 0, 1, 2, 2,
0, 0, 1, 1, 2)),
row.names = c(NA, -20L), class = "data.frame",
.Names = c("plant_sp", "skipped"))
As you can see, variable skipped has the values "0", "1" or "2". I need that per each plant_id (which is the group_by variable), that when its' first rows are "1" at skipped column, row will be deleted until a change at skipped column.
for example in my DF:
plant_sp skipped
1 plant_1 1
2 plant_1 1
3 plant_1 0
4 plant_1 1
5 plant_1 2
6 plant_2 0
7 plant_2 1
8 plant_2 1
9 plant_2 0
10 plant_2 2
11 plant_3 1
12 plant_3 0
13 plant_3 1
14 plant_3 2
15 plant_3 2
16 plant_4 0
17 plant_4 0
18 plant_4 1
19 plant_4 1
20 plant_4 2
TO:
plant_sp skipped
plant_sp skipped
3 plant_1 0
4 plant_1 1
5 plant_1 2
6 plant_2 0
7 plant_2 1
8 plant_2 1
9 plant_2 0
10 plant_2 2
12 plant_3 0
13 plant_3 1
14 plant_3 2
15 plant_3 2
16 plant_4 0
17 plant_4 0
18 plant_4 1
19 plant_4 1
20 plant_4 2
As you can see, since group "planet_1" and group "planet_2" started with "1", all rows with "1" at variable skipped at the begining were deleted (rows 1 and 2). All other rows stayed as they are.
if it is possible, a dplyr solution would be great, Thanks a lot!!!