Created
November 4, 2020 17:35
-
-
Save brownag/0086505000aaaa6998cbcb902d253d41 to your computer and use it in GitHub Desktop.
Logical splitting of single-profile horizon-level data into multi-profile SoilProfileCollections
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(aqp) | |
library(soilDB) | |
data(loafercreek) | |
# find hzdesgn with t in it | |
loafercreek$hasT <- grepl("t", horizons(loafercreek)$hzname) | |
# create a combined dataset where the horizons above first t subscript have "_above" suffix | |
# and the horizons below have "_below" | |
res <- aqp::combine(profileApply(loafercreek, function(p) { | |
p.firstT <- which(p$hasT) | |
if(length(p.firstT)) | |
p.firstT <- p.firstT[1] | |
else | |
p.firstT <- nrow(p) | |
p.above <- p[,1:(p.firstT-1)] | |
if(p.firstT != nrow(p)) { | |
p.below <- p[,p.firstT:nrow(p)] | |
profile_id(p.above) <- paste0(profile_id(p.below),"_above") | |
profile_id(p.below) <- paste0(profile_id(p.below),"_below") | |
return(aqp::combine(p.above, p.below)) | |
} else { | |
return(p.above) | |
} | |
})) | |
plot(subset(res, grepl("above|below", profile_id(res)))[1:10,]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment