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.
Seems the example is using a raster::stack() / RasterStack as input, whereas you are using a terra::rast / SpatRaster
I don't do geographical analysis myself often enough to tell you what to do to address, but I would look in that direction.