This function helps to create the corr_map dataframe for the offset correction. Based on the Date input, it creates a new section variable and maps it to all SAMPLE_NO.
Arguments
- df
(dataframe) The gasdata-dataframe.
- start
(vector, Date) A vector of type Date that specifies the starting date of each section (the starting date is included in the section!).
- end
(vector, Date) A vector of type Date that specifies the end date of each section (the end date is included in the section!). The start date of element i should be the end date of (i-1) +1 day.
- mode
(vector, character) A vector of type character that specifies the correction method to be used in each section. Valid methods are "const", here the median value is being used as a constant factor, and "lin", where a linear model is fit against time, to account for an temporal drift.
Examples
{
data("gasdata")
library(dplyr)
gasdata <- gasdata %>%
mutate(depth_cat = ifelse(depth>0,"HU","MIN"),
SAMPLE_NO = row_number())
cmap <-
offset_subsetting(gasdata,
start = "2021-01-01",
end = "2022-01-01",
mode = "const")
offset_correction(gasdata,
corr_map = cmap,
gases = "CO2",
gases_std = 400e-6,
depth_cal = "HU")
}
#> Joining with `by = join_by(Date, SAMPLE_NO)`
#> Joining with `by = join_by(gas)`
#> Adding missing grouping variables: `section`
#> Joining with `by = join_by(Date, gas)`
#> # A tibble: 624 × 9
#> # Groups: gas, section [1]
#> section Date gas corr_fac site depth x_ppm depth_cat SAMPLE_NO
#> <int> <date> <chr> <dbl> <chr> <dbl> <dbl> <chr> <int>
#> 1 1 2021-01-01 CO2 0.952 site_a 5 403. HU 1
#> 2 1 2021-01-01 CO2 0.952 site_a 0 526. MIN 2
#> 3 1 2021-01-01 CO2 0.952 site_a 0 529. MIN 3
#> 4 1 2021-01-01 CO2 0.952 site_a 0 530. MIN 4
#> 5 1 2021-01-01 CO2 0.952 site_a -10 682. MIN 5
#> 6 1 2021-01-01 CO2 0.952 site_a -10 679. MIN 6
#> 7 1 2021-01-01 CO2 0.952 site_a -10 689. MIN 7
#> 8 1 2021-01-01 CO2 0.952 site_a -20 759. MIN 8
#> 9 1 2021-01-01 CO2 0.952 site_a -20 779. MIN 9
#> 10 1 2021-01-01 CO2 0.952 site_a -20 759. MIN 10
#> # ℹ 614 more rows