分组之间的相关性 [英] correlation between columns by group

查看:89
本文介绍了分组之间的相关性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不使用列名的情况下计算R中数据框中的一列与所有其他列之间的相关性?我尝试使用ddply,如果我仅使用两个列名,则可以使用它.

How do I calculate correlations between one column and all other columns in a data frame in R without using column names? I tried to use ddply and it works if I use just two column names i.e.

library(plyr)
ddply(iris, ~Species, summarize, cormat=cor(Sepal.Length,Petal.Width)) 

但是如何在不使用列名的情况下,按物种将列1与所有其他列相关联?

But how to get correlations of column 1 with all other columns, broken down by Species, without using the column names?

推荐答案

也许像这样吗?它为每个物种生成一个相关矩阵.

Maybe like this? It produces a correlation matrix for each species.

by(iris [,1:4],iris $ Species,cor)

这篇关于分组之间的相关性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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