Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 206278

R: removing obs. only if a value of a column is present for the same (duplicate) id

$
0
0

I'm currently working in R with a data table containing two columns: id and type. The type value can be female, male, or both. There are instances where ID is repeated with differing values of Type. I'd like to delete obs. with Type==Both but only if obs. for the same ID are present that have a type == female and type==male.

This is my current table:

    id    type
    1     both
    1     female
    1     male
    2     both
    2     female
    3     both
    3     male
    3     female
    4     both
    5     male
    6     female

I'd like the table to resemble the following:

    id    type
    1     female
    1     male
    2     both
    2     female
    3     male
    3     female
    4     both
    5     male
    6     female

*obs with type==both are only deleted if the same id also contains type==female and type==male


Viewing all articles
Browse latest Browse all 206278

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>