将数字数据框拆分为 R 中 2 列的所有可能组合

Split a numeric dataframe into all possible combinations of 2 columns in R

我正在尝试拆分数据框的列以从包含 n 列的数据框中找到(两个)列的所有可能组合的 pmcc,例如在这种情况下,有 3 列 长径高

0.455 0.365 0.095
0.350 0.265 0.090
0.530 0.420 0.135
0.440 0.365 0.125
0.330 0.255 0.22

在这里我必须找到所有组合的 pmcc,例如,(长度,直径),(直径,高度)等。 任何帮助! 谢谢

data.frame(z = rnorm(100, 2), y = rnorm(100, 4), x = rnorm(100, 6)) -> frame
combn(colnames(frame), 2) -> combos
apply(combos, 2, function(x) cor(frame[,x[1]], frame[,x[2]]))