library(magrittr)
library(dplyr)
# LAD profiles derived from normalized ALS data after applying [lad.profile()] function
LAD_profiles <- read.table(system.file("extdata", "LAD_profiles.txt", package = "LadderFuelsR"),
header = TRUE)
LAD_profiles$treeID <- factor(LAD_profiles$treeID)
trees_name1 <- as.character(LAD_profiles$treeID)
trees_name2 <- factor(unique(trees_name1))
metrics_precentile_list1<-list()
for (i in levels(trees_name2)) {
tree1 <- LAD_profiles |> dplyr::filter(treeID == i)
metrics_precentil <- get_gaps_fbhs(tree1, step=1,
min_height=1.5,
perc_gap= 25,perc_base= 25,
verbose=TRUE)
metrics_precentile_list1[[i]] <- metrics_precentil
}
metrics_all_percentil <- dplyr::bind_rows(metrics_precentile_list1)
metrics_all_percentil$treeID <- factor(metrics_all_percentil$treeID)
# Remove the row with all NA values from the original data frame
# First remove "treeID" and "treeID1" columns
no_treeID <- metrics_all_percentil[, -which(names(metrics_all_percentil) == c("treeID","treeID1"))]
# Check if any row has all NA values
NA_or_zero <- apply(no_treeID, 1, function(row) all(is.na(row) | row == 0))
# Get the row index with all NA values
row_index <- which(NA_or_zero)
# Remove the row with all NA values from the original data frame
if (length(row_index) > 0) {
gap_cbh_metrics <- metrics_all_percentil[-row_index, ]
} else {
gap_cbh_metrics <- metrics_all_percentil
}
Run the code above in your browser using DataLab