-1

I'm looking to merge two dataframes and to create a barplot using geom_bar. One df1 has 5000 records (col1=ID,col2=activity category) and the second df2 has about 6,000 records (col1=ID,col2=Contact Method). My issue is that once I merge all of this info, it'll duplicate the info and basically multiply activity category with Contact Method by ID. Any idea on how to resolve this? image

camille
  • 16,432
  • 18
  • 38
  • 60
Aman
  • 27
  • 6
  • 2
    Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269). This will make it much easier for others to help you. – zx8754 Aug 16 '18 at 20:35
  • I guess, you have many-to-many relationships on ID column. Please provide example data and expected output. – zx8754 Aug 16 '18 at 20:36

1 Answers1

0

What it sounds like to me is you need to learn how to merge data frame by one category. If so see the first two likes of code. If you are just looking to stack one data frame on another, then a simple rbind will do the trick.

merge two data frames by ID

    mergedDataFrame <- merge(data_frameA,data_frameB,by="ID")

merging by two catagories

    mergedDataFrame <- merge(data_frameA,data_frameB,by=c("ID","2nd Identifier"))

The rbind function will simply place your second data frame below your first.

    stackedDataFrame <- rbind(data_frameA, data_frameB, data_frameC, ....)