gpt4 book ai didi

r - 如何在 R 中将一个矩阵的 upper.tri 与另一个矩阵的 lower.tri 结合起来?

转载 作者:行者123 更新时间:2023-12-04 10:50:22 25 4
gpt4 key购买 nike

我有两个相同长度的对称矩阵(一个包含相关系数,另一个包含 p 值)。

我正在尝试制作一个矩阵,使 upper.tri 包含相关系数,而 lower.tri 包含相关的 p 值。

最佳答案

假设您的矩阵是 correlpval

# create a new matrix that is the pvalues
new <- pval
# not sure what you want the diagonal to be, lets make it NA
diag(new) <- NA
# replace the upper triangle of this new matrix with the
# upper triangle of the correlation matrix
new[upper.tri(new)] <- correl[upper.tri(correl)]

关于r - 如何在 R 中将一个矩阵的 upper.tri 与另一个矩阵的 lower.tri 结合起来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13115720/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com