我正在try 将列名对称的矩阵转换为更低的三角形矩阵.这与常规问题不同,因为我的矩阵没有对称的值,因此清除上半部分的值是不起作用的.这将需要对行和列进行重组.这是矩阵.
mat_before <- structure(c(0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0,
0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1,
0, 0, 0, 0, 0), .Dim = c(8L, 8L), .Dimnames = list(c("Features", "Innovation", "KPI", "Knowledge", "Performance", "Presence",
"Trust", "VFM"), c("Features", "Innovation", "KPI", "Knowledge",
"Performance", "Presence", "Trust", "VFM")))
> mat_before
Features Innovation KPI Knowledge Performance Presence Trust VFM
Features 0 0 0 1 1 0 0 0
Innovation 0 0 0 0 0 1 0 0
KPI 0 1 0 0 1 0 1 1
Knowledge 0 0 0 0 0 1 0 0
Performance 0 0 0 1 0 1 0 0
Presence 0 0 0 0 0 0 0 0
Trust 1 0 0 0 0 0 0 0
VFM 0 1 0 0 0 0 0 0
这是重构后所需的结果(转换为下三角矩阵格式).
> matrix_result
Presence Knowledge Performance Innovation Features Trust VFM KPI
Presence 0 0 0 0 0 0 0 0
Knowledge 1 0 0 0 0 0 0 0
Performance 1 1 0 0 0 0 0 0
Innovation 1 0 0 0 0 0 0 0
Features 0 1 1 0 0 0 0 0
Trust 0 0 0 0 1 0 0 0
VFM 0 0 0 1 0 0 0 0
KPI 0 0 1 1 0 1 1 0
如果您有任何提示或技巧,我们将不胜感激. 编辑:我还需要这个代码可以复制到任何矩阵,这可能是对称的维度,但不同的大小和列名.