Convert radians to degree / degree to radians

40,555

Solution 1

The comment of Pascal was very useful and I found several ones, e.g.

install.packages("NISTunits", dependencies = TRUE)
library(NISTunits)

NISTdegTOradian(180)
NISTradianTOdeg(pi)

Solution 2

You can use the units package for this.

library(units)
pi_rad <- as_units(pi, "radians")
pi_deg <- set_units(pi_rad, "degrees")
set_units(pi_deg, "radians")
Share:
40,555

Related videos on Youtube

Iris
Author by

Iris

Hi, how R you? :)

Updated on October 04, 2020

Comments

  • Iris
    Iris over 3 years

    Are there build-in functions in R for the conversion of radians to degree and degree to radians?

    So far I wrote my one own functions:

    rad2deg <- function(rad) {(rad * 180) / (pi)}
    deg2rad <- function(deg) {(deg * pi) / (180)}
    
    #test:
    rad2deg(pi) #180
    rad2deg(2*pi) #360
    deg2rad(180) #pi
    
    • Admin
      Admin over 8 years
      install.packages("sos", dependencies = TRUE); library(sos); findFn("convert degree to radian").
    • Iris
      Iris over 8 years
      Very useful! Thank you @Pascal
    • Antony
      Antony over 6 years
      I am a little surprised that after all these years, R doesn't have a built in function to convert between degree and radian! Must we install extension to support it? At this point, I'd rather take OP's solution to achieve what I need
  • Iris
    Iris almost 8 years
    It's unnecessary to write a loop: davis_2$radian_wd <- (davis_2$radian_wd*pi)/180 is enough