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")
Related videos on Youtube
Comments
-
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 over 8 years
install.packages("sos", dependencies = TRUE); library(sos); findFn("convert degree to radian")
. -
Iris over 8 yearsVery useful! Thank you @Pascal
-
Antony over 6 yearsI 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 almost 8 yearsIt's unnecessary to write a loop:
davis_2$radian_wd <- (davis_2$radian_wd*pi)/180
is enough