0

i'm working on a project where I use the openair project. Specifically, I want to use the "timeAverage" function to average a dataset at daily time step, but when performing such a task, the variable wind direction won't be extracted. Here is the R code i'm using:

library("pmetar")
library("openair")
library("dplyr")
library("stringr")
NFTL<-metar_get_historical("NFTL", start_date = "2022-01-14", end_date = "2022-01-18", from = "iastate")
decoded_NFTL <- metar_decode(NFTL, metric = TRUE, altimeter = FALSE)

NFTL_obs<-select(decoded_NFTL, METAR_Date, Wind_direction)
NFTL_obs1 <- NFTL_obs 
NFTL_obs1$Wind_direction <- str_replace_all(NFTL_obs1$Wind_direction, 'Variable', 'NA')
NFTL_obs1$Wind_direction<-gsub(",.*","",NFTL_obs1$Wind_direction)
names(NFTL_obs1)[names(NFTL_obs1) == "METAR_Date"] <- "date"
names(NFTL_obs1)[names(NFTL_obs1) == "Wind_direction"] <- "wd"
daily <- timeAverage(NFTL_obs1, avg.time = "day")

In this example, you can check that the wind direction (wd) variable was not extracted when executing the last command from openair, how can I fix this?

  • It is possible that "wd" was a character type. You should convert it to numeric: `NFTL_obs1$wd <- as.numeric(NFTL_obs1$wd)` – Novvier Feb 28 '22 at 16:47
  • Thank you for the tip, this extra line in the code helped to correctly extract the wd varibale. – metroid2012 Mar 01 '22 at 23:02

1 Answers1

0

The reason to keep Wind_direction as the character is that sometimes the value is the text "Variable" or "variable from n1 to n2". You can use the function metar_dir for extracting wind directions as numeric.

NFTL_obs$Wind_direction <- metar_dir(NFTL, numeric_only = TRUE)

Waldi
  • 39,242
  • 6
  • 30
  • 78
Pablorcw
  • 1
  • 3