
UNSTABLE Fill missing soil horizon intervals by linear interpolation
fill_missing_layers.RdThis function fills missing depth intervals within a specified range by
interpolating TOCstock values using linear approximation between adjacent horizons.
Usage
fill_missing_layers(
data,
depth_from = 0,
depth_to = 0.3,
depth_top_var = "Depth_top",
depth_bottom_var = "Depth_bottom",
stock_var = "TOCstock",
group_vars = c("site_id", "Profile"),
min_thickness = 0.01
)Arguments
- data
A data frame containing soil horizon data.
- depth_from
Numeric. Lower bound of the depth interval to check (in meters).
- depth_to
Numeric. Upper bound of the depth interval to check (in meters).
- depth_top_var
Character. Name of the column containing the top depth of horizons (in meters).
- depth_bottom_var
Character. Name of the column containing the bottom depth of horizons (in meters).
- stock_var
Character. Name of the column containing the total stock per horizon (e.g., TOCstock in T/ha).
- group_vars
Character vector. Names of the grouping variables (e.g., site_id, Profile) used to group profiles.
- min_thickness
Numeric. Minimum gap (in meters) to consider as a missing horizon. Defaults to 0.01 (1 cm).
Value
A data frame with interpolated horizon layers added where gaps were detected within the target depth range.
New interpolated layers will have estimated TOCstock values based on the average stock density of adjacent layers.
Examples
df_filled <- fill_missing_layers(df, depth_from = 0, depth_to = 0.3,
depth_top_var = "Depth_top",
depth_bottom_var = "Depth_bottom",
stock_var = "TOCstock",
group_vars = c("site_id", "Profile"))
#> Error in sym(depth_top_var): could not find function "sym"