Convert Radian to Degree & Vice Versa in R (3 Examples)

 

In this tutorial, I’ll explain how to transform radian to degree and vice versa in the R programming language.

Table of contents:

Sound good? Great, let’s do this.

 

Example Data

The first step is to create some data that we can use in the following examples:

x <- 5.1784                              # Create example value
x                                        # Print example value
# [1] 5.1784

Have a look at the previous output of the RStudio console. It shows that our example data is a single numeric value stored in the data object x.

 

Example 1: Specify Radians Unit for Value Using as_units() Function of units Package

The following R programming code illustrates how to assign the radians unit to a numeric object.

We first need to install and load the units package, in order to use the corresponding functions:

install.packages("units")                # Install & load units
library("units")

In the next step, we can apply the as_units function to set the unit of our data object to radian:

x_rad <- as_units(x, "radians")          # Set value to radians unit
x_rad                                    # Print radians
# 5.1784 [rad]

 

Example 2: Convert Radians to Degree

The following R syntax shows how to convert radian to degree.

To accomplish this, we can use the set_units function of the units package as shown below:

x_deg <- set_units(x_rad, "degrees")     # Convert radians to degree
x_deg                                    # Print degree
# 296.7005 [°]

 

Example 3: Convert Degree to Radians

In Example 3, I’ll demonstrate how to transform degree to radian.

Once again, we can use the set_units function for this task:

x_rad2 <- set_units(x_deg, "radians")    # Convert degree to radians
x_rad2                                   # Print radians
# 5.1784 [rad]

As you can see, the output above shows the same value as our example data object x that we have created at the beginning of the tutorial.

This is because we have converted our data object from radian to degree and back to radian.

 

Video, Further Resources & Summary

Do you need further information on the contents of this article? Then you might watch the following video on my YouTube channel. I illustrate the R syntax of the present post in the video.

 

 

In addition, you might read the other R tutorials on my website. You can find a selection of articles that are related to the transformation of radian to degree and vice versa below.

 

In summary: At this point you should have learned how to convert and change radian to degree and vice versa in the R programming language. Don’t hesitate to tell me about it in the comments, if you have further questions.

 

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.

The maximum upload file size: 2 MB. You can upload: image. Drop file here

Top