Error message: "[app] the number of values returned by 'fun' is not appropriate" for simple correlation

What is terra? Oh I see, it's an R package.

I had a look at the link, thanks. I have never worked with raster data so I am no sure how much help I can be but I think we need to see all of your code and a sample of your data. See FAQ: How to do a minimal reproducible example ( reprex ) for beginners for some suggestions.

A handy way to supply some sample data is the dput() function. In the case of a large dataset something like dput(head(mydata, 100)) should supply the data we need. I aw not sure if we need both the raster data and the csv data or just the csv data.

Michael's code is assuming a single vector (stack) but if I understand you correctly you are looking at two different vecters of data, so I do not understand why cor(x_cor_1, y_cor_2) will not work.

Please give us some sample data.