简体   繁体   English

诊断错误:当 x 是矩阵时,不能指定 nrow 或 ncol

[英]diag error: nrow or ncol cannot be specified when x is a matrix

Error in diag(nrow(V) * tausq, nrow = ncol(V), ncol = ncol(V)) : 'nrow' or 'ncol' cannot be specified when 'x' is a matrix diag(nrow(V) * tausq, nrow = ncol(V), ncol = ncol(V)) 中的错误:当“x”是矩阵时,不能指定“nrow”或“ncol”

This is the error I get when I try to run这是我尝试运行时遇到的错误

D <- diag(nrow(V)*tausq, nrow=ncol(V), ncol=ncol(V))

which is part of a function I wrote.这是我编写的函数的一部分。

It's the first line of the function and V is a matrix which is part of the argument.它是函数的第一行,V 是一个矩阵,它是参数的一部分。

What does this error mean?这个错误是什么意思?

From ?diag , you can read that the function does one of two things -- it either extracts the main diagonal of a passed matrix or it constructs a new diagonal matrix.?diag ,您可以了解到该函数执行以下两件事之一——它要么提取传递矩阵的主对角线,要么构造一个新的对角矩阵。 If you are trying to extract the main diagonal of a matrix (by passing a matrix as the first argument to diag ), then you can't pass the nrow and ncol arguments to the diag function.如果您正试图(通过传递矩阵作为第一个参数来提取矩阵的主对角线diag ),那么你就无法通过nrowncol参数的diag功能。

The error is telling you that apparently nrow(V)*tausq is a matrix in your code -- since nrow(V) is a constant, we conclude that tausq must be a matrix.错误告诉您显然nrow(V)*tausq是您代码中的矩阵——因为nrow(V)是一个常数,我们得出结论tausq必须是一个矩阵。 As a result, it's giving you an error due to setting nrow and ncol .其结果是,它给你一个错误,由于设置nrowncol

Long story short -- you seem to be assuming nrow(V)*tausq is a constant, but in fact it's a matrix.长话短说——你似乎假设nrow(V)*tausq是一个常数,但实际上它是一个矩阵。 You need to convert tausq to a constant to proceed as you want to.您需要将tausq转换为常量才能按需要进行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 diag(csvfiles[, x:ncol(csvfiles)]) 中的错误:(list) object 不能被强制输入“double” - Error in diag(csvfiles[, x:ncol(csvfiles)]) : (list) object cannot be coerced to type 'double' 在R中按nrow或ncol移位矩阵 - Shifting matrix by nrow or ncol in R R:矩阵中的误差(0,nrow = N,ncol = n.seq):非数字矩阵范围 - R: Error in matrix(0, nrow = N, ncol = n.seq) : non-numeric matrix extent 向`as.matrix`明确提供nrow和ncol不会创建尺寸 - Explicitly providing nrow and ncol to `as.matrix` does not create dimensions 使用多个 numericInput 的 actionButton 为 2 个矩阵输入的 ncol 和 nrow 生成值 - Using an actionButton for multiple numericInput to generate value for ncol and nrow of 2 matrix Input “1中的错误:ncol(x):长度为0的参数”在R中使用Amelia时 - “Error in 1:ncol(x) : argument of length 0” when using Amelia in R 错误:在Caret中使用Train时,nrow(x)== n不为TRUE - Error: nrow(x) == n is not TRUE when using Train in Caret 如何在闪亮的应用程序中将ui.R值输入为ncol和nrow值以进行矩阵定义? - How to input ui.R values as ncol and nrow values for matrix definition in shiny app? (p &lt;-ncol(X))== ncol(Y)在glmer中不是TRUE错误 - (p <- ncol(X)) == ncol(Y) is not TRUE error in glmer geefirth 给出错误“矩阵中的错误(x $ id,ncol = 1):&#39;数据&#39;必须是向量类型,是&#39;NULL&#39; - geefirth giving error "Error in matrix(x$id,ncol=1): 'data' must be of a vector type, was 'NULL'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM