Converting wind direction in angles to text words

后端 未结 15 781
执笔经年
执笔经年 2021-01-30 13:16

I have wind direction data coming from a weather vane, and the data is represented in 0 to 359 degrees.

I want to convert this into text format (compass rose) with 16 di

15条回答
  •  心在旅途
    2021-01-30 14:04

    I use R heavily and needed a solution for this. This is what I came up with and works well for all possible combinations I have fed it:

    degToCardinal <- function(degrees) {
      val <- as.integer((degrees / 22.5) + 0.5)
      arr <- c("N","NNE","NE","ENE","E","ESE", "SE", "SSE","S","SSW","SW","WSW","W","WNW","NW","NNW")
      return(arr[((val+1) %% 16)])
    }
    

提交回复
热议问题