mercredi 29 juillet 2020

How to delete rows in a data.frame by a specific condition?

I tried to delete some rows in a data.frame but can't solve do problem. Can anyone help?

This is the data.frame

   subj trial fix type
1     a     1   1    K
2     a     1   2    T
3     a     1   3    T
4     a     2   1    K
5     a     2   2    K
6     a     2   3    T
7     b     1   1    T
8     b     1   2    K
9     b     1   3    K
10    b     2   1    K
11    b     2   2    T
12    b     2   3    T

and I want for each subj, in each trial the row where T appears for the first time. The result should look like this:

   subj trial fix type
2     a     1   2    T
6     a     2   3    T
7     b     1   1    T
11    b     2   2    T

Aucun commentaire:

Enregistrer un commentaire