我是R的新手。我正在尝试替换相关图的主对角线(显然由它组成)。我已经为相关图创建了向量,并使用了cocron包中的cor()函数来创建相关图。我还创建了一个列表,其中包含我想要的值,而不是相关图中的值,由相关图矢量的内部可靠性组成。
library(cocron)
library(fmsb)
# defining correlated variables
JOB_ins = subset(df,select=c("q9","Rq10_new","q11","q12"))
INT_to_quit = subset(df,select=c("q13","q14","Rq15_new","q16"))
Employability = subset(df,select=c("q17","q18","q19","q20"))
Mobility_pref = subset(df,select=c("Rq21","Rq22","Rq23","Rq24","Rq25"))
Career_self_mgmt = subset(df,select=c("q26","q27","q28","q29","q30"
,"q31","q32","q33"))
# subsetting dataframes
x = subset(df,select=c(JOB_ins, INT_to_quit, Employability
,Mobility_pref,Career_self_mgmt))
#creating a correlation matrix
corrmat = cor(x)
#creating Cronbach Alpha reliabilities vector for diagonal replacement
dlist=list(round(CronbachAlpha(JOB_ins),2),round(CronbachAlpha(Int_to_quit),2)
,round(CronbachAlpha(Employability),2)
,round(CronbachAlpha(Mobility_pref),2)
,round(CronbachAlpha(Career_self_mgmt),2))
#replacing the main diagonal
diag(corrmat)=dlist
这样做我会替换主对角线,但似乎我也将我的相关图从矩阵转换为矢量。我知道如何防止这种情况发生或逆转?
答案 0 :(得分:0)
首先,您可以使用向量而不是列表,将c(round(CronbachAlpha(JOB_ins),2),...)
替换为matrix(c(1,2,3,4), nrow = 2)
其次,您可以轻松地将矢量转换为矩阵。例:
c(1,2,3,4)
会将 [,1] [,2]
[1,] 1 3
[2,] 2 4
向量转换为以下2x2矩阵:
var s = "[{role:staff, storeId: 1234}, {role:admin, storeId: 4321}]";