我有两个相同长度的对称矩阵(一个包含相关系数,另一个包含p值).
我试图建立一个矩阵,使得upper.tri包含相关系数,而lower.tri包含相关的p值.
mne*_*nel 10
假设你的矩阵是correl和pval
# 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)]
Run Code Online (Sandbox Code Playgroud)