问题
I am trying to split the columns of a dataframe to find pmcc of all possible combinations of (two)columns from a dataframe containing n columns, e.g. in this case, with 3 columns Length Diameter Height
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
here I have to find pmcc for all combinations, eg, (length, diameter), (diameter, height), etc. Any help! Thanks
回答1:
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]]))
来源:https://stackoverflow.com/questions/33313486/split-a-numeric-dataframe-into-all-possible-combinations-of-2-columns-in-r