When data and the weather measurements do not perfectly line up, perform a
linear interpolation between two weather measurements and merge the results
into the provided dataset. Only applies to numerical weather columns (see
weather for more details).
Arguments
- data
Dataframe. Data with dates or times to which weather data should be added.
- weather
Dataframe. Weather data downloaded with
weatherwhich should be interpolated and added todata.- cols
Character. Vector containing the weather columns to add or 'all' for all relevant columns. Note that some measure are omitted because they cannot be linearly interpolated (e.g., wind direction).
- interval
What interval is the weather data recorded at? "hour" or "day".
- na_gap
How many hours or days (depending on the interval) is it acceptable to skip over when interpolating over NAs (see details).
Details
Dealing with NA values If there are NAs in the weather data,
na_gap can be used to specify a tolerance. For example, a tolerance of
2 with an interval of "hour", means that a two hour gap in data can be
interpolated over (i.e. if you have data for 9AM and 11AM, but not 10AM, the
data between 9AM and 11AM will be interpolated. If, however, you have 9AM and
12PM, but not 10AM or 11AM, no interpolation will happen and data between 9AM
and 12PM will be returned as NA.)
@inheritSection weather_dl Verbosity
Examples
if (FALSE) { # check_eccc()
# Weather data only
kamloops
# Data about finch observations at RFID feeders in Kamloops, BC
finches
# Match weather to finches
# First line up the timezones
# - Finches are in Pacific Time (inc. Daylight savings),
# Kamloops is in Pacific Time *without* daylight savings, but is marked as UTC for
# simplicity (see ?weather_dl for details)
# - First we convert finches to remove daylight savings, then we mark as UTC
finches <- dplyr::mutate(finches, time = lubridate::with_tz(time, "Etc/GMT+8"))
finches <- dplyr::mutate(finches, time = lubridate::force_tz(time, "UTC"))
# Then interpolate over the first 30 observations
finch_weather <- weather_interp(data = finches[1:30,], weather = kamloops)
}
