我想在两组变量之间建立一个相关矩阵。在第一组中,我有9个变量,在第二组中,我有24个变量。第二组变量包括第一组的9个变量。
例如
这是我的两套。
dep <- c("anxiety", "avoidance", "NEURO", "EXTRA","AGREE", "OPEN", "CONSC", "socialt", "solitaryt")
indep <-c("anxiety", "EXTRA", "NEURO", "CONSC", "OPEN",
"avoidance", "AGREE", "RMTQ", "RSE", "selfcontrol", "socialt",
"solitaryt", "riska", "stress", "socialdiversity", "networksize", "socialdiversity",
"socialembedded", "rwa", "lonely", "SDO", "DASSD", "DASSA", "WEMWBS")
答案 0 :(得分:0)
如果有人遇到相同的问题,我找到了解决方法。
df1 <- dat[, names(dat)%in% c("EXTRA", "NEURO", "CONSC", "OPEN", "AGREE", "anxiety",
"avoidance", "socialt","solitaryt", "RMTQ", "RSE", "selfcontrol","riska", "stress", "socialdiversity", "networksize", "socialdiversity"
,"socialembedded", "rwa", "lonely", "SDO", "DASSD", "DASSA", "WEMWBS")]
df2 <- dat[,names(dat)%in% c("EXTRA", "NEURO", "CONSC", "OPEN", "AGREE", "anxiety",
"avoidance", "socialt", "solitaryt")]
A <- as.matrix(df1)
B <- as.matrix(df2)
Matrice <- cor(A, B, use = "pairwise.complete.obs")