how to calculate the Euclidean norm of a vector in R?

后端 未结 10 1076
灰色年华
灰色年华 2021-02-01 13:22

I tried norm, but I think it gives the wrong result. (the norm of c(1, 2, 3) is sqrt(1*1+2*2+3*3), but it returns 6..

10条回答
  •  清酒与你
    2021-02-01 14:04

    This is a trivial function to write yourself:

    norm_vec <- function(x) sqrt(sum(x^2))
    

提交回复
热议问题