title: R - How to run duplicated for specific groups in my dataset?
body: <p>I have a data frame that contains a large amount of duplicate personal-ids by personnel working at different firms.</p>
  
  <p>I would like to use <strong><em>duplicated</em></strong> for the personal-ids for every different quarter within every different firm.</p>
  
  <p><img src="https://i.stack.imgur.com/lN0lp.png" alt="Example of what my data looks like"></p>
  
  <p>Basically, I would like R to run <strong><em>duplicated</em></strong> only for the ids within quarter 1 for firm 1, then for quarter 2 for firm 1, then quarter 3 for firm 1 etc. until the codes for firm 1 are done, and then move on to firm 2 where it runs duplicated again for quarter 1 for firm 2 etc.</p>
  
  <p><img src="https://i.stack.imgur.com/aVNoF.png" alt="Example of the desired result"></p>
  
  <p>My main issue is: If person A shows up in multiple different quarters or in multiple firms, the first time his/her id shows up within every quarter/firm <strong><em>should</em></strong> <strong><em>NOT</em></strong> be considered a duplicate value. </p>
  
  <p>Any input would be immensely appreciated and I will make sure to be swift with whatever clarifications may be needed. Thank you.</p>