# 1. check structure
data(ca630)
str(ca630)
# 2. extract site data and convert to SPDF
site <- ca630$site
coordinates(site) <- ~ lon + lat
# 3. aggregate CEC 7 for all profiles into 1 cm slices
# note intermediate steps... will be cleaned-up in AQP 1.0
lab <- ca630$lab
lab$prop <- lab$CEC_7
lab$id <- factor(lab$pedon_id)
s1 <- soil.slot(data=lab)
# 4. plot median & IQR by 1 cm slice
xyplot(top ~ p.q50 + p.q25 + p.q75,
data=s1, type='S', horizontal=TRUE, col=1, lty=c(1,2,2),
panel=panel.superpose, ylim=c(150,-5))
# 5. safely compute hz-thickness weighted mean CEC (pH 7)
lab.agg.cec_7 <- ddply(lab, .(pedon_id),
.fun=summarise, CEC_7=wtd.mean(CEC_7, weights=bottom-top))
# do something with the aggregated data now...
Run the code above in your browser using DataLab