# import raster image
data(normforest)
normforest <- terra::unwrap(normforest)
# locate peaks and valleys
peaks <- findpeaks(normforest)
valleys <- findvalleys(normforest)
# find top 5 peaks, valleys
top_peaks <- peaks[order(peaks$val, decreasing = TRUE)[1:5],]
bottom_valleys <- valleys[order(valleys$val)[1:5],]
# calculate the ten-point height
S10z <- (sum(top_peaks$val) + sum(abs(bottom_valleys$val))) / 5
Run the code above in your browser using DataLab