data(sp2)
depths(sp2) <- id ~ top + bottom
site(sp2) <- ~ surface
# get with [[
sp2[['surface']]
# get using "unknown" expression:
# "2nd + 3rd horizon column names"
for(i in horizonNames(sp2)[2:3])
print(sp2[[i]])
data(sp5)
# some column names to work with
rgb.columns <- c("R25","G25","B25")
res <- lapply(rgb.columns, function(x) {
# [[ allows you to access column names in a loop
round(sp5[[x]] * 255)
})
# rename scaled results
names(res) <- paste0(rgb.columns,"_scl")
# add horizon ID to results
result <- data.frame(hzID = hzID(sp5), do.call('cbind', res))
head(result)
# join result back into horizons
horizons(sp5) <- result
Run the code above in your browser using DataLab