Here is a df for example:
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(0, 0, 0, 1, 0,
0, 0, 1, 0, 0,
0, 0, 1, 0, 0,
0, 0, 1, 0,0)),
row.names = c(NA, -20L), class = "data.frame",
.Names = c("plant_sp", "skipped"))
I need the values in each group at the column "skipped" to be "0" if it comes before the "1" and "2" if it comes after. for exmaple at group "plant_1" I need it instead of beeing
"0,0,0,1,0" to be "0,0,0,1,2".
and at group 2 instead of
"0,0,1,0,0" to be "0,0,1,2,2".
a dplyr solution would be great!
Thanks a lot!