| tidy_TRHdata | R Documentation |
This function tidies and processes temperature, relative humidity, and date data from a given dataset. Dataset should minimally have "Date", "Temp" and "RH" columns.
It filters out rows with missing dates, attempts to parse dates, converts temperature and humidity to numeric types, and groups the data by Site, Sensor, and Date based on the averaging interval.
If the site or sensor columns are not present in the data, the function defaults to adding columns named "Site" and "Sensor". This can be changed in the arguments.
When an averaging option of "hour", "day", "month" is selected,
it uses dplyr and lubridate functions to floor datetimes and calculate averages,
the default is median average.
See lubridate::floor_date() for rounding intervals.
Filters out rows with missing dates.
Renames columns for consistency.
Converts temperature and relative humidity to numeric.
Adds default columns "Site" and "Sensor" when missing or not supplied in args.
Rounds dates down to the nearest hour, day, or month as per avg_time.
Calculates averages for temperature and relative humidity according to avg_statistic.
Filters out implausible temperature and humidity values (outside -50-80°C and 0-100%RH).
tidy_TRHdata(
mydata,
Site = "Site",
Sensor = "Sensor",
Date = "Date",
Temp = "Temp",
RH = "RH",
avg_time = "none",
avg_statistic = "median",
avg_groups = c("Site", "Sensor"),
...
)
mydata |
A data frame containing TRH data. Ideally, this should have columns for "Site", "Sensor", "Date", "Temp" (temperature), and "RH" (relative humidity). The function requires at least the date, temperature, and relative humidity columns to be present. Site and sensor columns are optional; if missing, the function will add default columns named "Site" and "Sensor" respectively with values below. |
Site |
A string specifying the name of the column in |
Sensor |
A string specifying the name of the column in |
Date |
A string specifying the name of the column in |
Temp |
A string specifying the name of the column in |
RH |
A string specifying the name of the column in |
avg_time |
Character string specifying the averaging interval.
One of "none" (no averaging), "hour", "day", or "month", etc.
See |
avg_statistic |
Statistic for averaging; default is "median". |
avg_groups |
Character vector specifying grouping columns for time-averaging. These are then returned as factors. Default is c("Site", "Sensor"). |
... |
Additional arguments (currently unused). |
A tidy data frame with processed TRH data. When averaging, date times are floored, temperature and humidity are averaged, groups are factored, and implausible values filtered.
# mydata file
filepath <- data_file_path("mydata.xlsx")
mydata <- readxl::read_excel(filepath, sheet = "mydata", n_max = 10)
tidy_TRHdata(mydata)
tidy_TRHdata(mydata, avg_time = "hour")
mydata |> add_humidity_calcs() |> tidy_TRHdata(avg_time = "hour")
# Example usage: TRH_data <- tidy_TRHdata("path/to/your/TRHdata.csv")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.