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?
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)
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.