I have an relatively large array (242x240x2922). The first two dimensions are latitude and longitude, and the third dimension is time (daily satellite images).
I need to extract the correlation coefficient for a subset of that array that corresponds to data within a 6° Radius of each one of the (lon, lat) pairs. First, I created a loop that calculates the circle polygon for each of the lon, lat pairs. Then, I checked which points are inside the circle (with the point.in.polygon function), and extracted the subset of the larger array.
I know I could build a second, nested loop that can calculate the correlation of the time series of each lon, lat with the rest of the time series of the "sub array" (those that fall within the circle), but It would take too long... is there any straight forward way to calculate the correlation coefficient of a vector of size "L" with each of the vectors of an array that has NxMxL dimensions? For example, in a loop, the first round would calculate cor(myvector, myarray[,,1]).
I tried using apply(myarray, dim=3, cor), but I'm struggling to understand the results.
Thanks a lot in advance.