Please format the code properly for readability. If you can post your data too it would be easier for reproducing the error. Take a look at my post, where I've uploaded the data on web, so that anyone running my script can get the data easily, if needed. Also, could you try making a reprex ?