Your first post provided data, and FJCC kindly showed how to complete your requested task on that data, but your follow up message indicates that your data is different. Therefore please take a moment to make a reproducible example, such that it presents the issue you wish to solve.
I would really encourage you to review the following guide, FAQ: Tips for writing R-related questions. For example, the guide emphasizes asking coding questions with formatted code-chunks and a reprex
, which would make it easier for people who want to help you to pick up your issue and attempt to run with a solution.