我有一个向量e <- c(0.1, -0.1, 0.1)
,我想计算L1和L2规范。我使用的norm(e, type="2")
适用于L2规范,但当我将其更改为norm(e, type="1")
或norm(e, type="I")
时, R-Studio 会返回以下错误:
Error in norm(e, type = "1") : 'A' must be a numeric matrix
如何解决这个问题?
答案 0 :(得分:3)
要解决此问题,请使用e <- as.matrix(c(0.1, -0.1, 0.1))
。
正下方是规范函数的主体,如果type!="2"
,它将跳到.Internal(La_dlange(x,type))
,我想这会导致第2类特殊,但我无法进一步解释。< / p>
function (x, type = c("O", "I", "F", "M", "2"))
{
if (identical("2", type)) {
svd(x, nu = 0L, nv = 0L)$d[1L]
}
else .Internal(La_dlange(x, type))
}