
Aggregate Weather Observations to Daily Data
Source:R/aggregate_weather_daily.R
aggregate_weather_daily.RdConverts sub-daily weather observations to one row per day, optionally within
each site or location. The same statistics style used by the window
workflow is supported here: use a character vector to apply the same
statistics to every variable, or use a named list to choose different
statistics for different variables. The special .conditions entry can be
used for multivariable summaries within each daily group.
Usage
aggregate_weather_daily(
weather,
id_col = NULL,
time_col = "time",
date_col = "date",
weather_cols = NULL,
temp_col = "temp",
rh_col = "rh",
rain_col = "rain",
leaf_wetness_col = "leaf_wetness",
statistics = list(temp = "mean", rh = "mean", rain = "sum", leaf_wetness = "sum"),
keep_time = TRUE,
name_prefix = "daily"
)Arguments
- weather
A weather data frame.
- id_col
Optional site, location, or series identifier column. If supplied, aggregation is done separately within each ID.
- time_col
Name of the timestamp column. Use
NULLwhen the input data already have a day/date column and no separate timestamp column is needed.- date_col
Name of the day/date column. If this column already exists in
weather, it is used for daily grouping. If it does not exist,aggregate_weather_daily()derives it fromtime_coland creates it in the output.- weather_cols
Character vector of weather columns to aggregate. If named, the names are used in the output column names.
- temp_col
Name of the temperature column.
- rh_col
Name of the relative humidity column.
- rain_col
Name of the rainfall column.
- leaf_wetness_col
Name of the leaf wetness column.
- statistics
Daily statistics to compute. Use a character vector to apply the same statistics to all
weather_cols, such asc("mean", "max"). Use a named list to choose statistics by variable or to provide custom named functions. Use.conditionsfor multivariable condition summaries.- keep_time
If
TRUE, include a dailyPOSIXcttime column at midnight. This requires eithertime_color an existingdate_col.- name_prefix
Prefix used in aggregated weather columns. The default creates names such as
daily_mean_tempanddaily_sum_rain.
Examples
hourly <- simulate_weather_series(days = 5, n_series = 2, id_col = "site_id", seed = 1)
aggregate_weather_daily(
hourly,
id_col = "site_id",
statistics = list(temp = c("mean", "max"), rh = "mean", rain = "sum")
)
#> site_id date time daily_mean_temp daily_max_temp daily_mean_rh
#> 1 S01 2024-01-01 2024-01-01 22.51000 28.83 78.49250
#> 2 S01 2024-01-02 2024-01-02 22.96833 30.32 78.89083
#> 3 S01 2024-01-03 2024-01-03 23.64375 31.27 80.01708
#> 4 S01 2024-01-04 2024-01-04 23.65750 29.58 79.76667
#> 5 S01 2024-01-05 2024-01-05 23.27542 29.56 77.87917
#> 6 S02 2024-01-01 2024-01-01 22.55417 29.42 80.02417
#> 7 S02 2024-01-02 2024-01-02 22.77500 29.74 78.78000
#> 8 S02 2024-01-03 2024-01-03 23.02250 30.12 80.48500
#> 9 S02 2024-01-04 2024-01-04 23.52583 30.77 78.79875
#> 10 S02 2024-01-05 2024-01-05 23.15667 29.59 78.78292
#> daily_sum_rain
#> 1 3.48
#> 2 1.63
#> 3 3.52
#> 4 1.40
#> 5 3.23
#> 6 3.74
#> 7 1.30
#> 8 4.23
#> 9 8.02
#> 10 3.34