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
The comment of Pascal was very useful and I found several ones, eg
install.packages("NISTunits", dependencies = TRUE)
library(NISTunits)
NISTdegTOradian(180)
NISTradianTOdeg(pi)
If you have a data.frame It could help you
In my case davis_2$wd is the column in degree
#Add column to Data Base
davis_2$radian_wd = davis_2$wd
#Create a loop to change the data, and change the 62'th col to Radians
for(i in 1:nrow(davis_2)){
davis_2[i, 62] = (davis_2[i, 62]*pi)/180
}
# Review
head(davis_2$radian_wd)
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")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.