如何创建具有多个特定变量的相关矩阵?
我有一个很大的数据集,但是想执行一个相关矩阵,其中只有该数据集中的10个变量(并将变量名称命名为其他内容),
我的当前代码看起来像这样:
#Correlation Function
data.cor = cor(df)
#Correlation Coefficient
data.cor = cor(df, method = "pearson", use = "complete.obs")
#Running Correlation w/ P-Values
install.packages("Hmisc")
library("Hmisc")
data.rcorr = rcorr(as.matrix(df))
data.rcorr
#
data.coeff = data.rcorr$r
data.p = data.rcorr$P
但是,1) t工作2)我知道这只是参考完整数据集,
我该如何制作它,以便我只参考这10个变量并能够重命名变量?
事先谢谢你!
I have a very large data set, but want to do a correlation matrix with only 10 of the variables in that data set (and rename the variable names to something else)
My current code is looking like this:
#Correlation Function
data.cor = cor(df)
#Correlation Coefficient
data.cor = cor(df, method = "pearson", use = "complete.obs")
#Running Correlation w/ P-Values
install.packages("Hmisc")
library("Hmisc")
data.rcorr = rcorr(as.matrix(df))
data.rcorr
#
data.coeff = data.rcorr$r
data.p = data.rcorr$P
However, 1) it doesn't work 2) i am aware it is just reference the full data set
How can I make it so that I am referencing only those 10 variables and be able to rename the variables?
Thank you beforehand!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您有一个数据框
d
,您可以通过多种方式直接进行子集化。例如,使用变量名向量,如下所示:输出:
输入:
If you have a dataframe,
d
, you can directly subset in numerous ways. For example, using a vector of variable names, as below:Output:
Input: