Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于r中的字符串关联数据帧中的项_R_String_Correlation - Fatal编程技术网

基于r中的字符串关联数据帧中的项

基于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

我目前拥有数据集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  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")