From 568c5959925baa457d875a4c3fbb9618188c0d8a Mon Sep 17 00:00:00 2001 From: mrustl Date: Wed, 10 Jul 2024 13:40:47 +0200 Subject: [PATCH] Remove duplicated node_id soil zone is extended --- R/extend_soil_profile.R | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/R/extend_soil_profile.R b/R/extend_soil_profile.R index 8a94226..76a49c8 100644 --- a/R/extend_soil_profile.R +++ b/R/extend_soil_profile.R @@ -10,8 +10,12 @@ #' @importFrom dplyr arrange bind_rows #' extend_soil_profile <- function(df, x_end) { + + shorten_profile <- FALSE + if (x_end > min(df$x)) { if (any(x_end == df$x)) { + shorten_profile <- TRUE return(df[which(x_end <= df$x), ]) } } else { @@ -40,7 +44,11 @@ extend_soil_profile <- function(df, x_end) { } # Kombinieren und Sortieren der Dataframes - combined_df <- dplyr::bind_rows(df, new_df) + combined_df <- if(shorten_profile) { + dplyr::bind_rows(df, new_df) + } else { + dplyr::bind_rows(df, new_df[-1,]) + } sorted_df <- dplyr::arrange(combined_df, node_id) return(sorted_df)