Double function

See the FAQ: How to do a minimal reproducible example reprex for beginners. It's very troublesome to address a question like this without some data to work with.