data(codstom)
prey.types
)
collected by D. Chabot and
M. Hanson,
Fisheries & Oceans Canada (chabotd@dfo-mpo.gc.ca).ship.type
90 or 99) or by research vessels. Commercial
vessels are identified by a unique ship.id
.
Either
one research vessel or several commercial vessels conduct a survey
(trip
), during which a trawl, gillnets or hooked lines are set
several times. Most trips are random stratified surveys (depth-based
stratification).
Each trip takes place within one of the region
s. The
trip
label is only guaranteed to be unique within a region and
the set
label is only guaranteed to be unique within a
trip
.
For each fish caught, the fish.length
is recorded
and the fish is allocated a fish.id
, but the fish.id
is only guaranteed to be unique within a set
. A subset of the
fish caught are selected for stomach analysis (stratified random
selection according to fish length; unit of
stratification is the set for research surveys, the combination ship.id
and stratum for surveys conducted by commercial vessels, although strata
are not shown in codstom).
The basic experimental unit in this data set is a cod stomach
(one stomach per fish). Each stomach is uniquely identified by
a combination of region
, ship.type
, ship.id
,
trip
, set
, and fish.id
.
For each prey item found in a stomach,
the species and mass of the prey item are recorded, so there can be
multiple observations per stomach. There may also
be several prey items with the same prey.type
in the one
stomach (for example many prey.types
have been recoded Other
,
which produced many instances of Other
in the same stomach).
If a stomach is empty, a single observation is recorded
with prey.type
Empty
and a prey.mass
of zero.data(codstom)
str(codstom)
# removes multiple occurences of same prey.type in stomachs
codstom1 <- summaryBy(prey.mass ~
region+ship.type+ship.id+trip+set+fish.id+prey.type,
data = codstom, id = ~fish.length,
keep.names=TRUE, FUN = sum)
# keeps a single line per stomach with the total mass of stomach content
codstom2 <- summaryBy(prey.mass ~ region+ship.type+ship.id+trip+set+fish.id,
data = codstom, id = ~fish.length,
keep.names=TRUE, FUN = sum)
# mean prey mass per stomach for each trip
codstom3 <- summaryBy(prey.mass ~ region+ship.type+ship.id+trip,
data = codstom2, keep.names=TRUE, FUN = mean)
# wide version, one line per stomach, one column per prey type
library(reshape)
codstom4 <- melt(codstom, id = c(1:7, 9))
codstom5 <- cast(codstom4,
region+ship.type+ship.id+trip+set+fish.id+fish.length ~
prey.type, sum)
k <- length(names(codstom5))
prey_col <- 8:k
out <- codstom5[,prey_col]
out[is.na(out)] <- 0
codstom5[,prey_col] <- out
codstom5$total.content <- rowSums(codstom5[, prey_col])
Run the code above in your browser using DataLab