Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

generalize.hz

Generalize Horizon Names


Description

Generalize a vector of horizon names, based on new classes, and REGEX patterns.

Usage

generalize.hz(x, new, pat, non.matching.code = "not-used", hzdepm = NA, ...)

Arguments

x

a character vector of horizon names

new

a character vector of new horizon classes

pat

a character vector of REGEX, same length as x

non.matching.code

text used to describe any horizon not matching any item in pat

hzdepm

a numeric vector of horizon mid-points, must not contain NA, same length as x

...

additional arguments passed to grep() such as perl=TRUE for advanced REGEX

Value

factor of the same length as x

Author(s)

D.E. Beaudette

Examples

## Not run: 

data(sp1)

# check original distribution of hz designations
table(sp1$name)

# generalize
sp1$genhz <- generalize.hz(sp1$name,
                           new=c('O','A','B','C','R'),
                           pat=c('O', '^A','^B','C','R'))

# 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 <- generalize.hz(x, new = n, pat=p, perl=TRUE)

# double-check: OK
table(res, x)


## End(Not run)

aqp

Algorithms for Quantitative Pedology

v1.29
GPL (>= 3)
Authors
Dylan Beaudette [aut, cre], Pierre Roudier [aut, ctb], Andrew Brown [aut, ctb]
Initial release
2021-04-05

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.