# load some example data
data(sp1, package='aqp')
# upgrade to SoilProfileCollection
depths(sp1) <- id ~ top + bottom
# generalize horizon names
n <- c('O', 'A', 'B', 'C')
p <- c('O', 'A', 'B', 'C')
sp1$genhz <- generalize.hz(sp1$name, n, p)
# note: levels are in the order in which originally defined:
levels(sp1$genhz)
# generalize horizons by depth slice
s <- dice(sp1, c(5, 10, 15, 25, 50, 100, 150) ~ .)
s$slice <- paste0(s$top, ' cm')
# not a factor
levels(s$slice)
# the proper ordering of these new labels can be guessed from horizon depths
guessGenHzLevels(s, 'slice')
# convert to factor, and set proper order
s$slice <- factor(s$slice, levels=guessGenHzLevels(s, 'slice')$levels)
# that is better
levels(s$slice)
Run the code above in your browser using DataLab