mfdb_queries: MareFrame DB queries

Description Usage Arguments Details Value Examples

Description

Aggregate data from the database in a variety of ways

Usage

1
2
3
4
5
6
7
mfdb_area_size(mdb, params)
mfdb_temperature(mdb, params)
mfdb_sample_count(mdb, cols, params)
mfdb_sample_meanlength(mdb, cols, params)
mfdb_sample_meanlength_stddev(mdb, cols, params)
mfdb_sample_meanweight(mdb, cols, params)
mfdb_sample_meanweight_stddev(mdb, cols, params)

Arguments

mdb

An object created by mfdb()

cols

Any additonal columns to group by, see details.

params

A list of parameters, see details.

Details

The items in the params list either restrict data that is returned, or groups data if they are also in the cols vector, or are 'year', 'timestep', or 'area'.

If you are grouping by the column, params should contain one of the following:

NULL

Don't do any grouping, instead put 'any' in the resulting column. For example, age = NULL results in "any".

character / numeric vector

Aggregate all samples together where they match. For example, year = 1990:2000 results in 1990, ... , 2000.

mfdb_unaggregated()

Don't do any aggregation for this column, return all possible values.

mfdb_group()

Group several discrete items together. For example, age = mfdb_group(young = 1:3, old = 4:5) results in "young" and "old".

mfdb_interval()

Group irregular ranges together. For example, length = mfdb_interval('len', c(0, 10, 100, 1000)) results in "len0", "len10", "len100", and "len1000".

mfdb_step_interval()

Group regular ranges together. For example, length = mfdb_step_interval('len', to = 100, by = 10) results in "len0", "len10", ... , "len100".

In addition, params can contain other arguments to purely restrict the data that is returned.

institute

A vector of institute names, see mfdb::institute for possible values

gear

A vector of gear names, see mfdb::gear for possible values

vessel

A vector of vessel names, see mfdb::vessel for possible values

sampling_type

A vector of sampling_type names, see mfdb::sampling_type for possible values

species

A vector of species names, see mfdb::species for possible values

sex

A vector of sex names, see mfdb::sex for possible values

To save specifying the same items repeatedly, you can use list concatenation to keep some defaults, for example:

1
2
defaults <- list(year = 1998:2000)
mfdb_sample_meanlength(mdb, c('age'), c(list(), defaults))

Value

All will return a list of data.frame objects. Precisely what columns these will contain depends on the function called.

mfdb_temperature

Returns year, step, area, (mean) temperature

mfdb_sample_count

Returns year,step,area,(group cols),number (of samples)

mfdb_sample_meanlength

Returns year,step,area,(group cols),number (of samples),mean (length in group)

mfdb_sample_meanlength_stddev

As mfdb_sample_meanlength, but also returns std. deviation.

mfdb_sample_meanweight

Returns year,step,area,(group cols),number (of samples),mean (weight of group)

mfdb_sample_meanweight_stddev

As mfdb_sample_meanweight, but also returns std. deviation.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## Not run: 
agg_data <- mfdb_sample_count(mdb, c('age', 'length'),
        params = c(list(
            year = c(1990, 1991),
            length = mfdb_interval("len", seq(0, 500, by = 30)),
            age = mfdb_group('young' = c(1,2,3)),
            null = NULL), opt_catch))
gadget_dir_write(gd, gadget_likelihood_component("catchdistribution",
        name = "cdist",
        weight = 0.9,
        data = agg_data[[1]],
        area = attr(agg_data[[1]], "area"),
        age = attr(agg_data[[1]], "age")))

## End(Not run)

sCervino/mfdb documentation built on May 18, 2019, 1:31 p.m.