Calculate Euclidean Norm of Vector in R (Example)

 

In this R tutorial you’ll learn how to compute the Euclidean Norm.

The content of the post is structured like this:

Let’s start right away:

 

Creation of Example Data

We use the following data as basement for this R tutorial:

vec <- 1:10                          # Create example vector
vec                                  # Print example vector
#  [1]  1  2  3  4  5  6  7  8  9 10

Have a look at the previous output of the RStudio console. It shows that our example data is a numeric vector ranging from the values 1 to 10.

 

Example: Calculate Euclidean Norm Using norm Function & type Argument

This example illustrates how to compute the Euclidean Norm in R using the norm() function and the type argument.

To calculate the Euclidean Norm, we have to set the type argument to be equal to “2” within the norm function.

The explanation for this can be found in the help documentation of the norm function: type = “2” “specifies the “spectral” or 2-norm, which is the largest singular value (svd) of x”.

Have a look at the following R code:

vec_norm <- norm(vec, type = "2")    # Apply norm function
vec_norm                             # Print Euclidean Norm
# [1] 19.62142

The Euclidean Norm of our vector is 19.62142.

 

Video & Further Resources

I have recently released a video instruction on my YouTube channel, which shows the R programming code of this article. Please find the video below:

 

The YouTube video will be added soon.

 

Furthermore, you might read the related articles of my website:

 

In this article, I have illustrated how to return the Euclidean Norm of a vector in the R programming language. Tell me about it in the comments, in case you have additional questions. Furthermore, please subscribe to my email newsletter for updates on the newest articles.

 

Subscribe to my free statistics newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.


Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

Menu
Top