R 未能用向量填充矩阵的三角形部分:关于长度的警告

R 未能用向量填充矩阵的三角形部分:关于长度的警告,r,matrix,R,Matrix,我有一个向量要填充到矩阵的下三角部分。但我有一个警告信息 par1 <- 0.5:7 par1 <- sample(par1, 496, replace = T) par11 <- matrix(0, 32, 32) par11[lower.tri(par11, diag = TRUE)] <- par1 Warning message: In par11[lower.tri(par11, diag = TRUE)] <- par1 : number of

我有一个向量要填充到矩阵的下三角部分。但我有一个警告信息

par1 <-  0.5:7
par1 <- sample(par1, 496, replace = T)
par11 <- matrix(0, 32, 32)
par11[lower.tri(par11, diag = TRUE)] <- par1

Warning message:
In par11[lower.tri(par11, diag = TRUE)] <- par1 :
  number of items to replace is not a multiple of replacement length

par1矩阵中的三角形部分(没有主对角线)有
nx(N-1)/2个元素。如果包括主对角线,则在添加参数时会出现
nx(N+1)/2

,然后长度从496变为496+32=528。因此向量不相等。您不使用diag=T,或者您可以采样528