vecnorm(x, p = 2)
The numerical value of a norm may differ for vectors which have the same elements appearing in a different order. Sorting a vector so that the elements of smallest modulus appear first may help reduce this roundoff error.
x <- rnorm(100)sqrt(sum(x*x)) vecnorm(x)
x <- rep(sqrt(.Machine$double.xmax), 4) sqrt(sum(x*x)) vecnorm(x)
sum(abs(x)) vecnorm(x, p = 1)
max(abs(x)) vecnorm(x, p = Inf)