data(sp1)
# check original distribution of hz designations
table(sp1$name)
# generalized horizon labels
# character vector input
sp1$genhz <- generalizeHz(
sp1$name,
new = c('O','A','B','C','R'),
pattern = c('O', '^A','^B','C','R'),
ordered = TRUE
)
# see how we did / what we missed
table(sp1$genhz, sp1$name)
## a more advanced example, requries `perl = TRUE`
# example data
x <- c('A', 'AC', 'Bt1', '^AC', 'C', 'BC', 'CB')
# new labels
n <- c('A', '^AC', 'C')
# patterns:
# "A anywhere in the name"
# "literal '^A' anywhere in the name"
# "C anywhere in name, but without preceding A"
p <- c('A', '^A', '(?A)C')
# note additional argument
res <- generalizeHz(
x,
new = n,
pattern = p,
perl = TRUE
)
# double-check: OK
table(res, x)
## apply to a SoilProfileCollection
data(sp1)
depths(sp1) <- id ~ top + bottom
# must set horizon designation metadata
hzdesgnname(sp1) <- 'name'
# result is a SoilProfileCollection
x <- generalizeHz(
sp1,
new = c('O','A','B','C','R'),
pattern = c('O', '^A','^B','C','R'),
ordered = TRUE
)
# GHL stored in 'genhz' column
x$genhz
# GHL metadata is set
GHL(x)
Run the code above in your browser using DataLab