基于r中的字符串关联数据帧中的项
我目前拥有数据集newdat,一个包含项目分数的数据框架:基于r中的字符串关联数据帧中的项,r,string,correlation,R,String,Correlation,我目前拥有数据集newdat,一个包含项目分数的数据框架: set.seed(1) newdat <- setNames(data.frame(replicate(5,sample(1:5,10,replace=TRUE))),paste0("i",1:5)) i1 i2 i3 i4 i5 1 2 2 5 3 5 2 2 1 2 3 4 3 3 4 4 3 4 4 5 2 1 1 3 5 2 4 2 5 3 6 5
set.seed(1)
newdat <- setNames(data.frame(replicate(5,sample(1:5,10,replace=TRUE))),paste0("i",1:5))
i1 i2 i3 i4 i5
1 2 2 5 3 5
2 2 1 2 3 4
3 3 4 4 3 4
4 5 2 1 1 3
5 2 4 2 5 3
6 5 3 2 4 4
7 5 4 1 4 1
8 4 5 2 1 3
9 4 2 5 4 4
10 1 4 2 3 4
set.seed(1)
newdat如果您只想计算特定的相关性,您可以选择要传递到cor的列
cor(newdat[newDV], newdat[!(names(newdat) %in% c(newCV, newDV))],
use="complete.obs")
cor(newdat[newDV],newdat[!(名称(newdat)%in%c(newCV,newDV)),使用=“complete.obs”)
@user20650是看起来不错,请作为答案提交!
corr<-cor(newdat,use="complete.obs")[-which(colnames(newdat)==c(newCV,newDV)),which(colnames(newdat)==c(newCV,newDV))]
cor(newdat[newDV], newdat[!(names(newdat) %in% c(newCV, newDV))],
use="complete.obs")