How to only select rows that are duplicated in a column in a dataframe

Hey all,

I have joined two dataframes together and I am trying to select only the 'Branch Codes' that are duplicated.

However, the last line of the code below does not seem to work!

BranchData$'Branch Code' <- as.numeric(BranchData$'Branch Code')
BranchCalls$'Branch Code' <- as.numeric(BranchCalls$'Branch Code')
BranchData <- na.omit(BranchData)
merged <- full_join(BranchData,BranchCalls)
merged <- merged %>% group_by(merged$`Branch Code`) %>% filter(n() >= 2)

Also, when I try to put the duplicates into groups, so that all the duplicates are together, but the following code doesn't seem to work!:

merged <- group_by(merged,merged
$'Branch Code')

Minimal Reproducible Example:

`Branch Code` `Location Type` Type  Status Segment `Multiple (partn…` RetailType `Volume of tra…` `Open hours` `X Pos` `Y Pos`
          <dbl> <chr>           <chr> <chr>  <chr>   <chr>              <chr>                 <dbl>        <dbl>   <dbl>   <dbl>
1        401801 Urban           MAIN  Open   Agency  Multiple 11        Books_Sta…             2238         47.7  394169  806326
2        436801 Urban           MAIN  Open   Agency  Multiple 11        Books_Sta…             1514         50.3  393488  805877
3        403801 Urban Deprived  MAIN  Open   Agency  Multiple 12        Convenien…             1346         46.5  394434  804347
4        164801 Rural           MAIN  Open   Agency  Multiple 13        Convenien…             1338         48.3  392153  796902
5        198801 Urban           LM    Open   Agency  Multiple 13        Convenien…              625        114.   393094  802789
6        442801 Rural           LM    Open   Agency  Multiple 9         Convenien…              588         40.3  383644  800648
#

I would be so grateful if anybody could give me a helping hand!

Thank you so much!

Hi @eyavuz21 ,

Including a snapshot of your data at the end of your question was a great; however, it would be better to give us a way to be able to handle it ourselves. This will enable us to write code that we can test directly on the data. You can use the dput() function on the piece of data you want to share, then copy and paste the output of the function.

Hi @gueyenono,

My issue here has now been solved! Thank you so much for your help :slight_smile:

BW,

Emre

It seems that you have not pasted the full output. Could you please check it?

THank you.

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.