Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Logical splitting of single-profile horizon-level data into multi-profile SoilProfileCollections
# 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(loafercreekfunction(p) {
  p.firstT <- which(p$hasT)
    p.firstT <- p.firstT[1]
    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 {
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