I have a vector e <- c(0.1, -0.1, 0.1)
and I want to calculate L1 and L2 norms. I am using norm(e, type="2")
which works fine for L2 norm but when I change it to norm(e, type="1")
or norm(e, type="I")
, R-Studio returns following error:
Error in norm(e, type = "1") : 'A' must be a numeric matrix
How to resolve this?
To solve the problem, usee <- as.matrix(c(0.1, -0.1, 0.1))
.
right below is the body of the norm function, if type!="2"
, it will skip to .Internal(La_dlange(x,type))
, I guess this cause type 2 special but I can't give any further explain.
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))
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With