dbW_substituteWeather: Replace missing values with values from another weather data...

View source: R/swWeatherGenerator.R

dbW_substituteWeatherR Documentation

Replace missing values with values from another weather data set

Description

Replace missing values with values from another weather data set

Usage

dbW_substituteWeather(
  weatherData,
  subData,
  vars_substitute = NULL,
  by = NULL,
  by_weatherData = by,
  by_subData = by,
  return_weatherDF = FALSE
)

Arguments

weatherData

A list of elements of class swWeatherData or a data frame as returned by dbW_weatherData_to_dataframe().

subData

A weather data object.

vars_substitute

Names of variables for which missing values in weatherData should be replaced by values from subData. If NULL, then all weather variables (i.e., weather_dataColumns()).

by

Names of variables used to match days (rows) between weatherData and subData. If NULL, then all variables occurring both in weatherData and subData that are not weather variables.

by_weatherData

See by.

by_subData

See by.

return_weatherDF

A logical value. See section "Value".

Value

An updated copy of weatherData where missing values have been replaced by corresponding values from subData. If return_weatherDF is TRUE, then the result is converted to a data frame where columns represent weather variables. If return_weatherDF is FALSE, then the result is a list of elements of class swWeatherData.

See Also

dbW_generateWeather(), dbW_imputeWeather()

Examples

# Load example data
path_demo <- system.file("extdata", "example1", package = "rSOILWAT2")
dif <- c(rep(TRUE, 3L), rep(FALSE, 11L))
dif[13L] <- TRUE # ACTUAL_VP
dif[14L] <- TRUE # SHORT_WR, desc_rsds = 2
wdata <- getWeatherData_folders(
  LookupWeatherFolder = file.path(path_demo, "Input"),
  weatherDirName = "data_weather_daymet",
  filebasename = "weath",
  startYear = 1980,
  endYear = 1981,
  dailyInputFlags = dif,
  method = "C"
)
x0 <- x <- dbW_weatherData_to_dataframe(wdata)
dif0 <- calc_dailyInputFlags(x0)

# Set June-August of 1980 as missing
ids_1980 <- x[, "Year"] == 1980
ids_missing <- ids_1980 & x[, "DOY"] >= 153 & x[, "DOY"] <= 244
x[ids_missing, -(1:2)] <- NA

# Substitute missing values
all.equal(
  dbW_substituteWeather(x, x0[ids_1980, ], return_weatherDF = TRUE),
  x0
)



Burke-Lauenroth-Lab/Rsoilwat documentation built on Dec. 9, 2023, 12:41 a.m.