vendredi 24 avril 2020

Removing a group with conditional statement in r

The conditional statement is that in any event, if there are more than two consecutive rows with values higher than 1, the group should be deleted.

For example:

Event<- c(1,1,1,1,2,2,2,2,2,2,3,3,3,3,3)
Value<- c(1,0,0,0,8,7,1,0,0,0,8,0,0,0,0)
A<- data.frame(Event, Value)

Event   Value
  1       1
  1       0
  1       0
  1       0
  2       8
  2       7
  2       1
  2       0
  2       0
  2       0
  3       8
  3       0
  3       0
  3       0
  3       0

In this example the group of event 2 should be deleted because it has more than two consecutive rows with values higher than 1. So it should looks like:

Event   Value
  1       1
  1       0
  1       0
  1       0
  3       8
  3       0
  3       0
  3       0
  3       0

Any suggestion?

Aucun commentaire:

Enregistrer un commentaire