data(sp1)
# create a SoilProfileCollection from horizon data
depths(sp1) <- id ~ top + bottom
# create random site-level attribute `sitevar` with a binary (0/1) outcome
sp1$sitevar <- round(runif(length(sp1)))
# use denormalize() to create a mirror of sitevar in the horizon table
# name the attribute something different (e.g. `hz.sitevar`) to
# prevent collision with the site attribute
# the attributes can have the same name but you will then need
# site() or horizons() to access explicitly
sp1$hz.sitevar <- denormalize(sp1, 'sitevar')
# compare number of profiles to number of sitevar assignments
length(sp1)
table(sp1$sitevar)
# compare number of horizons to number of horizon-level copies of sitevar `hz.'sitevar`
nrow(sp1)
table(sp1$hz.sitevar)
Run the code above in your browser using DataLab