r - calculate moving window correlation coefficients between one x and hundreds of y variables, then create a new dataframe of r-values -


i calculate 11-year moving window pearson correlation coefficients between 1 column of temperature data , growth many plants (e.g., hundreds thousands of plants). here's limited example of dataframe like:

dat <- as.data.frame(rbind(c(1945,11.4,0.508,0.160,0.419,0.255), c(1946,12.5,0.065,0.127,0.881,0.541),                          c(1947,12.4,0.162,0.142,0.539,0.447), c(1948,12.9,0.274,0.102,0.862,0.728),                        c(1949,11.1,0.284,0.042,1.863,0.126), c(1950,13.0,0.015,0.109,1.925,0.142),                        c(1951,13.3,0.001,0.160,1.585,0.245), c(1952,12.2,0.233,0.033,1.199,0.076),                        c(1953,13.4,0.169,0.123,1.729,0.529), c(1954,12.6,0.135,0.166,1.754,0.171),                        c(1955,11.7,0.275,0.167,1.389,0.382), c(1956,11.9,0.092,0.032,0.697,0.325),                        c(1957,13.3,0.054,0.105,1.387,0.178), c(1958,13.4,0.311,0.041,1.585,0.593))) names(dat)<-c("year", "temp", "plant1", "plant2", "plant3", "plant4") dat    year temp plant1 plant2 plant3 plant4 1  1945 11.4  0.508  0.160  0.419  0.255 2  1946 12.5  0.065  0.127  0.881  0.541 3  1947 12.4  0.162  0.142  0.539  0.447 4  1948 12.9  0.274  0.102  0.862  0.728 5  1949 11.1  0.284  0.042  1.863  0.126 6  1950 13.0  0.015  0.109  1.925  0.142 7  1951 13.3  0.001  0.160  1.585  0.245 8  1952 12.2  0.233  0.033  1.199  0.076 9  1953 13.4  0.169  0.123  1.729  0.529 10 1954 12.6  0.135  0.166  1.754  0.171 11 1955 11.7  0.275  0.167  1.389  0.382 12 1956 11.9  0.092  0.032  0.697  0.325 13 1957 13.3  0.054  0.105  1.387  0.178 14 1958 13.4  0.311  0.041  1.585  0.593 

i recognize can done in running package of gtools. however, i'm concerned output. create dataframe of correlation coefficients looks this:

dat <- as.data.frame(rbind(c(1950,-0.72,0.22,0.25,0.35), c(1951,-0.55,0.47,0.12,0.33),                          c(1952,-0.61,0.43,0.13,0.24), c(1953,-0.39,0.29,0.15,0.36))) names(dat)<-c("year", "rplant1", "rplant2", "rplant3", "rplant4") dat   year rplant1 rplant2 rplant3 rplant4 1 1950   -0.72    0.22    0.25    0.35 2 1951   -0.55    0.47    0.12    0.33 3 1952   -0.61    0.43    0.13    0.24 4 1953   -0.39    0.29    0.15    0.36 

in "year" mid-point of 11 year moving window. forward suggestions!


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -