data(sp4)
depths(sp4) <- id ~ top + bottom
mutate_profile(sp4, clay_wtd_average = weighted.mean(clay, bottom - top))
data(jacobs2000)
set.seed(123)
## col_names allows for column names to be calculated
x <- mutate_profile(jacobs2000, bottom - top / sum(bottom - top),
col_names = paste0("relthk", floor(runif(1, 0, 100))))
x$relthk28
# mutate_profile_raw allows for lists of expressions to be evaluated
master_desgn <- c("O", "A", "E", "B", "C", "R", "L", "M")
thk_names <- paste0("thk_", master_desgn)
# calculate thickness for each horizon
x$thk <- x$bottom - x$top
## construct an arbitrary number of expressions using variable inputs
ops <- lapply(master_desgn, function(x) {
substitute(sum(thk[grepl(PATTERN, name)], na.rm = TRUE), list(PATTERN = x))
})
names(ops) <- thk_names
# do mutation
y <- mutate_profile_raw(x, ops)
site(y)[c(idname(y), thk_names)]
Run the code above in your browser using DataLab