Hello,
You probably have some sort of missings or NAs getting introduced. So you will have to check each part of your code. You'll need to share code for us to see what's going on. See here: FAQ: How to do a minimal reproducible example ( reprex ) for beginners
If you just simply want to calculate mean with NAs in you can do:
mean(df, na.rm = TRUE)