Remove rows with a unique value in one column? Help


shared_conflicts <- df %>%
                 group_by(dispnum) %>%

Hi there,

Apologies if this is a bit of a stupid question or if I've not used the correct terminology but I'm very new to this stuff. In fact I've reworded this whole box many-times so I'm hoping it actually makes sense.

The data-set I am using is very large. Its purpose is to show conflicts between countries. I will note what the columns are called and what they mean.

  • dispnum - the unique dispute identifier code. (i.e. if two rows have same dispnum it means they were in the same dispute)
  • ccode - numerical code for countries, for my purposes I am looking at USA (ccode == 2) and China (ccode == 710)
  • sidea - which side the country was on within the dispute (e.g. if this was WW2, UK = 0, GER = 1 meaning they were on opposite sides)

I want to produce a new data-set which removes all of the rows where the dispnum is unique (i.e. not shared by another row).

The end goal is to basically show if the number of disputes between US-China has increased/decreased over the years but need to get through this stage first! Where it is such a big dataset I'm trying to do this in the easiest way possible. A screenshot from the set is below and as you can see there are two rows which have the same dispnum. I would ideally just like to produce a new sheet which shows only those two rows which have the same dispnum (or something along those lines...) is it possible?


See the FAQ: How to do a minimal reproducible example reprex for beginners.

Something like this


counts <- DF %>% filter(ccode ==  2 | ccode = 710) %>% group_by(dispnumb) %>% count()
dupes <- counts > 2
DF2 <- DF %>% filter(dispnumb %in% dupes) %>% filter(ccode != 2 | 710) 

This may not work because it was not run against data.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.