mercredi 17 mars 2021

If Group Contains Value Logic R

I'm trying to get the age given certain criteria. For example, if RNA is not null, then I would like to have the AvatarKey be associated with the minimum age associated with a present RNA entry. If, however, it is NA, I would like to take the minimum Age where DNA is not null. If both are null, remove.

Input:

ID       DNA     RNA     Age
2        NA      SL43    22.2
2        SL333   NA      55.7
2        SL333   SL43    43.7
6        SL333   NA      10.3
6        SL333   NA      65.6
6        NA      NA      35.5
5        NA      SL43    78.0
5        NA      SL43    23.3
5        NA      SL43    35.8
7        SL333   SL43    13.5
7        SL333   SL43    98.1
1        NA      NA      55.6

Desired Output

ID       DNA     RNA     Age
2        NA      SL43    22.2
2        SL333   SL43    43.7
6        SL333   NA      10.3
5        NA      SL43    23.3
7        SL333   SL43    13.5

Aucun commentaire:

Enregistrer un commentaire