Hi, and welcome!
See FAQ: What's a reproducible example (`reprex`) and how do I do one?
At a minimum, representative data is essential to follow the question. If you have a data frame named, for instance, dat
dput(dat)
and cut and paste into the question.