## structure of default, empty SoilProfileCollection
str(SoilProfileCollection())
## use the depths() formula interface to specify
## profile ID, top and bottom depth and set up
## a SPC that is topologically correct and complete
d <- do.call('rbind', lapply(1:10, random_profile))
# promote to SoilProfileCollection and plot
depths(d) <- id ~ top + bottom
plot(d)
# split into new SoilProfileCollection objects by index
d.1 <- d[1, ]
d.2 <- d[2, ]
d.345 <- d[3:5, ]
# combine profile collections
# note that profiles are sorted according to ID
d.new <- c(d.345, d.1, d.2)
plot(d.new)
data(sp1)
## init SoilProfileCollection objects from data.frame
depths(sp1) <- id ~ top + bottom
## depth units
du <- depth_units(sp1)
depth_units(sp1) <- 'in'
depth_units(sp1) <- du
## horizon designation column
hzdesgnname(sp1) <- "name"
hzdesgnname(sp1)
## all designations in an SPC (useful for single profile SPC)
hzDesgn(sp1)
## horizon texture class column
hztexclname(sp1) <- "texture"
hztexclname(sp1)
## get/set metadata on SoilProfileCollection objects
# this is a 1-row data.frame
m <- metadata(sp1)
m$sampler <- 'Dylan'
metadata(sp1) <- m
## extract horizon data from SoilProfileCollection objects as data.frame
h <- horizons(sp1)
# also merge (left-join) of new columns and
# replacement of existing columns via horizons<-
horizons(sp1) <- h
# get number of horizons
nrow(sp1)
## getting site-level data
site(sp1)
## setting site-level data
# site-level data from horizon-level data (stored in @horizons)
site(sp1) <- ~ group
# make some fake site data, and append from data.frame
# a matching ID column must be present in both @site and new data
# note that IDs should all be character class
d <- data.frame(id=profile_id(sp1), p=runif(n=length(sp1)), stringsAsFactors=FALSE)
site(sp1) <- d
# edit horizon depths
horizonDepths(sp1) <- c('t', 'b')
horizonDepths(sp1)
# edit profile IDs
p <- sprintf("%s-new", profile_id(sp1))
profile_id(sp1) <- p
profile_id(sp1)
Run the code above in your browser using DataLab