10.38 Wind Directions

20180723 The three wind direction variables (wind_gust_dir, wind_dir_9am, wind_dir_3pm) are also identified as character. We review the distribution of values here with dplyr::select() identifying any variable that tidyr::contains() the string _dir and then build a vctrs::table() over those variables.

# Review the distribution of observations across levels.

ds %>%
  select(contains("_dir")) %>%
  sapply(table)
##     wind_gust_dir wind_dir_9am wind_dir_3pm
## N           13806        17553        13369
## NNE         10358        12645        10551
## NE          11402        11887        12981
## ENE         12884        12351        12356
## E           14449        14595        12999
## ESE         11947        12532        13414
## SE          14670        14647        16406
## SSE         13997        14323        14179
## S           14195        13436        15062
## SSW         13992        11958        12973
## SW          13731        13000        14086
## WSW         13948        10703        14718
## W           15263        12799        15451
## WNW         12707        11712        13744
## NW          12376        13110        13005
## NNW         10234        12058        11860

Observe all 16 compass directions are represented and it would make sense to convert this into a factor. Notice that the directions are in alphabetic order and conversion to factor will retain that. Instead we can construct an ordered factor to capture the compass order (from N, NNE, to NW and NNW). We note the ordering of the directions here.

# Levels of wind direction are ordered compas directions.

compass <- c("N", "NNE", "NE", "ENE",
             "E", "ESE", "SE", "SSE",
             "S", "SSW", "SW", "WSW",
             "W", "WNW", "NW", "NNW")


Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0