Simple tests for horizon logic, based on a simple data.frame of ordered horizons.
test_hz_logic(i, topcol, bottomcol, strict = FALSE)
i that describes horizon top depthi that describes horizon bottom depthBy default, this function tests for NA and overlapping horizons. If any either are encountered, FALSE is returned.
logical: TRUE --> pass, FALSE --> fail
http://casoilresource.lawr.ucdavis.edu/
depths<-
## simple example: just one profile data(sp1) depths(sp1) <- id ~ top + bottom s <- horizons(sp1[1, ]) ## check # fails due to missing hz boundary s$bottom[6] <- NA # missing horizon boundary, common on bottom-most hz test_hz_logic(s, 'top', 'bottom', strict=FALSE) # fails due to inconsistent hz boundary s$bottom[3] <- 30 # inconsistent hz boundary test_hz_logic(s, 'top', 'bottom', strict=TRUE) ## filtering bad data ## Not run: ------------------------------------ # # missing bottom horizons # x$hzn_bot[!is.na(x$hzn_top) & is.na(x$hzn_bot)] <- x$hzn_top[!is.na(x$hzn_top) & is.na(x$hzn_bot)] # # # remove O horizons where top > bottom # bad.O.hz.idx <- which(x$hzn_top > x$hzn_bot) # if(length(bad.O.hz.idx) > 0) # x <- x[-bad.O.hz.idx, ] ## --------------------------------------------- ## checking for bad data: do this before promoting to SoilProfileCollection object library(plyr) data(sp1) # horizon logic can be tested via data.frame, at 2 levels of scrutiny: ddply(sp1, 'id', test_hz_logic, topcol='top', bottomcol='bottom', strict=FALSE) ddply(sp1, 'id', test_hz_logic, topcol='top', bottomcol='bottom', strict=TRUE)