Trim FLR objects using named dimensions
Usage
trim(x, ...)
# S4 method for class 'FLArray'
trim(x, ...)
# S4 method for class 'FLComp'
trim(x, ...)
# S4 method for class 'FLS'
trim(x, ...)
# S4 method for class 'FLBiol'
trim(x, ...)
Details
Subsetting of FLR objects can be carried out with dimension names by using
trim
. A number of dimension names and selected dimensions are passed
to the method and those are used to subset the input object.
Exceptions are made for those classes where certain slots might differ in
one or more dimensions. If trim is applied to an FLQuant object of length 1
in its first dimension and with dimension name equal to 'all', values to
trim
specified for that dimension will be ignored. For example,
FLStock
objects contain slots with length=1 in their first
dimension. Specifying values to trim over the first dimension will have no
effect on those slots (catch
, landings
, discards
, and
stock
). Calculations might need to be carried out to recalculate
those slots (e.g. using computeCatch
, computeLandings
,
computeDiscards
and computeStock
) if their quant-structured
counterparts are modified along the first dimension.
Examples
flq <- FLQuant(rnorm(90), dimnames=list(age=1:10, year=2000:2016))
trim(flq, year=2000:2005)
#> An x of class "FLQuant"
#> , , unit = unique, season = all, area = unique
#>
#> year
#> age 2000 2001 2002 2003 2004 2005
#> 1 -0.2804 -0.4302 0.1207 -0.8483 1.4400 1.3521
#> 2 0.0528 0.3445 0.1210 0.7353 -0.4845 -1.0571
#> 3 -1.9228 -0.4711 1.2270 0.3713 0.3287 -0.0622
#> 4 -0.4890 -0.5506 -1.5407 -1.5414 -0.2663 -0.3596
#> 5 0.6503 0.5543 -0.1285 0.0648 0.5033 -0.8437
#> 6 -0.1782 0.7260 0.3789 -2.2543 -0.4660 0.3594
#> 7 1.8028 -1.5689 0.3068 1.7820 0.4924 -0.3425
#> 8 1.0422 -0.0145 0.1859 0.8159 0.7894 -0.1417
#> 9 0.5913 -0.5914 0.8516 -0.3136 -0.1230 2.5203
#> 10 0.5127 -1.2037 0.1657 1.1386 0.3372 1.8478
#>
#> units: NA
# which is equivalent to
window(flq, start=2000, end=2005)
#> An x of class "FLQuant"
#> , , unit = unique, season = all, area = unique
#>
#> year
#> age 2000 2001 2002 2003 2004 2005
#> 1 -0.2804 -0.4302 0.1207 -0.8483 1.4400 1.3521
#> 2 0.0528 0.3445 0.1210 0.7353 -0.4845 -1.0571
#> 3 -1.9228 -0.4711 1.2270 0.3713 0.3287 -0.0622
#> 4 -0.4890 -0.5506 -1.5407 -1.5414 -0.2663 -0.3596
#> 5 0.6503 0.5543 -0.1285 0.0648 0.5033 -0.8437
#> 6 -0.1782 0.7260 0.3789 -2.2543 -0.4660 0.3594
#> 7 1.8028 -1.5689 0.3068 1.7820 0.4924 -0.3425
#> 8 1.0422 -0.0145 0.1859 0.8159 0.7894 -0.1417
#> 9 0.5913 -0.5914 0.8516 -0.3136 -0.1230 2.5203
#> 10 0.5127 -1.2037 0.1657 1.1386 0.3372 1.8478
#>
#> units: NA
trim(flq, year=2000:2005, age=1:2)
#> An x of class "FLQuant"
#> , , unit = unique, season = all, area = unique
#>
#> year
#> age 2000 2001 2002 2003 2004 2005
#> 1 -0.2804 -0.4302 0.1207 -0.8483 1.4400 1.3521
#> 2 0.0528 0.3445 0.1210 0.7353 -0.4845 -1.0571
#>
#> units: NA
# Now on an FLStock
data(ple4)
summary(trim(ple4, year=1990:1995))
#> An object of class "FLStock"
#>
#> Name: PLE
#> Description: Plaice in IV. ICES WGNSSK 2018. FLAAP
#> Quant: age
#> Dims: age year unit season area iter
#> 10 6 1 1 1 1
#>
#> Range: min max pgroup minyear maxyear minfbar maxfbar
#> 1 10 10 1990 1995 2 6
#>
#> Metrics:
#> rec: 550376 - 1083810 (1000)
#> ssb: 222203 - 396458 (t)
#> catch: 132629 - 250604 (t)
#> fbar: 0.60 - 0.61 (f)
# If 'age' is trimmed in ple4, catch, landings and discards need to be
# recalculated
shpl4 <- trim(ple4, age=1:4)
landings(shpl4) <- computeLandings(shpl4)
discards(shpl4) <- computeDiscards(shpl4)
catch(shpl4) <- computeCatch(shpl4)
summary(shpl4)
#> An object of class "FLStock"
#>
#> Name: PLE
#> Description: Plaice in IV. ICES WGNSSK 2018. FLAAP
#> Quant: age
#> Dims: age year unit season area iter
#> 4 61 1 1 1 1
#>
#> Range: min max pgroup minyear maxyear minfbar maxfbar
#> 1 4 NA 1957 2017 2 4
#>
#> Metrics:
#> rec: 367450 - 4303680 (1000)
#> ssb: 91016 - 316967 (t)
#> catch: 36219 - 253152 (t)
#> fbar: 0.22 - 0.71 (f)