将数字数据框拆分为R中2列的所有可能组合 [英] Split a numeric dataframe into all possible combinations of 2 columns in R

查看:89
本文介绍了将数字数据框拆分为R中2列的所有可能组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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,例如,(长度,直径),(直径,高度)等. 任何帮助! 谢谢

here I have to find pmcc for all combinations, eg, (length, diameter), (diameter, height), etc. Any help! Thanks

推荐答案

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]]))

这篇关于将数字数据框拆分为R中2列的所有可能组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆